package com.yuyou.fn.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.github.wens.mybatisplus.plugins.Page;
import com.yuyou.fn.analyze.service.*;
import com.yuyou.fn.analyze.vo.*;
import com.yuyou.fn.common.entity.Sms;
import com.yuyou.fn.common.exception.BusException;
import com.yuyou.fn.common.service.ISiteConfigService;
import com.yuyou.fn.common.service.ISmsService;
import com.yuyou.fn.common.util.BeanUtils;
import com.yuyou.fn.common.util.TimeUtils;
import com.yuyou.fn.common.util.Utils;
import com.yuyou.fn.common.vo.SmsQueryVo;
import com.yuyou.fn.educational.entity.BaseGrade;
import com.yuyou.fn.educational.entity.CourseClass;
import com.yuyou.fn.educational.entity.Period;
import com.yuyou.fn.educational.entity.Product;
import com.yuyou.fn.educational.service.*;
import com.yuyou.fn.educational.vo.*;
import com.yuyou.fn.platform.entity.AreaTeam;
import com.yuyou.fn.platform.entity.SysUser;
import com.yuyou.fn.platform.permission.DataPermission;
import com.yuyou.fn.platform.service.IAreaTeamService;
import com.yuyou.fn.report.vo.*;
import com.yuyou.fn.settlement.entity.ChangeRecord;
import com.yuyou.fn.settlement.entity.MainAccount;
import com.yuyou.fn.settlement.service.IChangeRecordService;
import com.yuyou.fn.settlement.vo.ChangeRecordQueryVo;
import com.yuyou.fn.settlement.vo.FeeCategoryTreeMapVo;
import com.yuyou.fn.tradingservice.service.IServiceMerchantService;
import com.yuyou.fn.util.Webs;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;
import java.util.*;
import java.util.concurrent.ExecutionException;

/**
 * Created by itachi on 2017/04/05.
 */
@Controller
@RequestMapping("/api/admin/analyze")
public class AdminAnalyzeController extends ApiBaseController {

    @Resource
    private IMainAccountTargetService mainAccountTargetService;

    @Resource
    private IProductTargetService productTargetService;

    @Resource
    private IServiceMerchantService serviceMerchantService;

    @Resource
    private IBusinessStatisticsService businessStatisticsService;

    @Resource
    private IPeriodService periodService;

    @Resource
    private IProductStatisticsService productStatisticsService;

    @Resource
    private IProductService productService;

    @Resource
    private ISiteConfigService siteConfigService;

    @Resource
    private IGradeAndSubjectStatisticsService gradeAndSubjectStatisticsService;

    @Resource
    private IDataStatisticsService dataStatisticsService;

    @Resource
    private IReportConfigService reportConfigService;

    @Resource
    private ICourseClassService courseClassService;

    @Resource
    private ITeacherTargetService teacherTargetService;

    @Resource
    private IClassTargetService classTargetService;

    @Resource
    private IIndexStatisticsService indexStatisticsService;

    @Resource
    private IRefundStatisticsService refundStatisticsService;

    @Resource
    private IChangeRecordService changeRecordService;

    @Resource
    private IAreaTeamService areaTeamService;

    @Resource
    private IExternalRegDetailService externalRegDetailService;

    @Resource
    private IBaseGradeService baseGradeService;

    @Resource
    private ISmsService smsService;

    @Resource
    private ICourseOrderDiscountService courseOrderDiscountService;

    @Resource
    private IRefundBonusPersonService refundBonusPersonService;

    @ApiOperation("获取对应期数")
    @RequestMapping(value = "/periodByYearAndAreaTeamId" ,method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<List<Period>> periodByYearAndAreaTeamId(@RequestParam(value = "areaTeamId")Long areaTeamId,@RequestParam(value = "year") String year,HttpServletRequest request){
        List<Period> periodList=periodService.findByYearAndAreaTeamId(areaTeamId,year);
        return ReturnResult.success(periodList);
    }


    @ApiOperation("业务组营收或者利润目标（营收targetType：0，利润targetType：1）")
    @RequestMapping(value = "/mainAccountTargetList" ,method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<List<MainAccountTargetResultVo>> mainAccountTargetList(@RequestParam(value = "busTeamId")long busTeamId,@RequestParam(value = "year") String year, HttpServletRequest request){
        List<MainAccountTargetResultVo> mapList=mainAccountTargetService.findListByBusTeamIdAndYear(busTeamId,year);
        return ReturnResult.success(mapList);
    }

    @ApiOperation("区域年级科目预收目标")
    @RequestMapping(value = "/areaTeamGradeSubjectTarget" ,method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<List<MainAccountTargetResultVo>> areaTeamGradeSubjectTarget(@RequestParam(value = "areaTeamId")long areaTeamId,@RequestParam(value = "year") String year, HttpServletRequest request){
        List<MainAccountTargetResultVo> mapList=mainAccountTargetService.findAreaTeamGradeSubjectTarget(areaTeamId,year);
        return ReturnResult.success(mapList);
    }


    @ApiOperation("保存目标信息")
    @RequestMapping(value = "/saveOrUpdateMainAccountTarget",method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Void> saveOrUpdateMainAccountTarget(@RequestParam(value = "mainAccountId")Long mainAccountId,@RequestParam(value = "year") String year,@RequestParam(value = "targetType")String targetType, @RequestParam(value = "mainAccountTargetVoJson") String mainAccountTargetVoJson, HttpServletRequest request){
        List<MainAccountTargetVo> mainAccountTargetVoList = null;
        if (StringUtils.isNotEmpty(mainAccountTargetVoJson)) {
            mainAccountTargetVoList = JSONObject.parseArray(mainAccountTargetVoJson, MainAccountTargetVo.class);
        }
        if (mainAccountTargetVoList == null) {
            return ReturnResult.fail("缺少目标信息");
        }
        mainAccountTargetService.insertByList(mainAccountId,year,targetType,mainAccountTargetVoList);
        return ReturnResult.success("保存成功");
    }



    @ApiOperation("产品线营收或者利润目标（营收targetType：0，利润targetType：1）")
    @RequestMapping(value = "/productTargetList",method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Page<ProductTargetResultVo>> productTargetList(ProductQueryVo productQueryVo, @RequestParam(value = "year") String year, @RequestParam(value = "targetType")Integer targetType,@RequestParam(value = "pageNo") int pageNo,@RequestParam(value = "pageSize") int pageSize, HttpServletRequest request){
        Page<ProductTargetResultVo> productTargetResultVoPage=productTargetService.findPages(productQueryVo,getDataPermission(request),pageNo,pageSize,year,targetType);
        return ReturnResult.success(productTargetResultVoPage);
    }

    @ApiOperation("保存产品目标信息")
    @RequestMapping(value = "/saveOrUpdateProductTarget",method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Void> saveOrUpdateProductTarget(@RequestParam(value = "productId")Long productId,@RequestParam(value = "year") String year,@RequestParam(value = "targetType")Integer targetType, @RequestParam(value = "productTargetVoJson") String productTargetVoJson, HttpServletRequest request){
        List<ProductTargetVo> productTargetVoList = null;
        if (StringUtils.isNotEmpty(productTargetVoJson)) {
            productTargetVoList = JSONObject.parseArray(productTargetVoJson, ProductTargetVo.class);
        }
        if (productTargetVoList == null) {
            return ReturnResult.fail("缺少目标信息");
        }
        productTargetService.insertByList(productId,year,targetType,productTargetVoList);
        return ReturnResult.success("保存成功");
    }


    @ApiOperation("班主任目标")
    @RequestMapping(value = "/teacherTargetList" ,method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Page<TeacherTargetResultVo>> teacherTargetList(@ModelAttribute TeacherQueryVo teacherQueryVo, @RequestParam(value = "year") String year, @RequestParam(value = "pageNo") int pageNo, @RequestParam(value = "pageSize") int pageSize, HttpServletRequest request){
        Page<TeacherTargetResultVo> page=teacherTargetService.findPageByBusTeamIdAndYear(teacherQueryVo,getDataPermission(request),year,pageNo,pageSize);
        return ReturnResult.success(page);
    }

    @ApiOperation("保存班主任目标")
    @RequestMapping(value = "/saveTeacherTarget" ,method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Void> saveTeacherTarget(@RequestParam(value = "teacherTargetVoJson") String teacherTargetVoJson,@RequestParam(value = "teacherId")Long teacherId,@RequestParam(value = "targetType")Integer targetType,@RequestParam(value = "year") String year, HttpServletRequest request){
        List<TeacherTargetVo> teacherTargetVoList = null;
        if (StringUtils.isNotEmpty(teacherTargetVoJson)) {
            teacherTargetVoList = JSONObject.parseArray(teacherTargetVoJson, TeacherTargetVo.class);
        }
        if (teacherTargetVoList == null) {
            return ReturnResult.fail("缺少目标信息");
        }
        teacherTargetService.insertByList(teacherId,year,targetType,teacherTargetVoList);
        return ReturnResult.success("ok");
    }

    @ApiOperation("班级目标列表")
    @RequestMapping(value = "/classTargetList" ,method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Page<ClassTargetVo>> classTargetList(@ModelAttribute CourseClassQueryVo courseClassQueryVo, @RequestParam(value = "pageNo") int pageNo, @RequestParam(value = "pageSize") int pageSize, HttpServletRequest request){
        Page<ClassTargetVo> page=classTargetService.findPage(courseClassQueryVo,getDataPermission(request),pageNo,pageSize);
        return ReturnResult.success(page);
    }


    @ApiOperation("保存班级目标")
    @RequestMapping(value = "/saveClassTarget" ,method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Void> saveClassTarget(@ModelAttribute ClassTargetSaveVo classTargetSaveVo, HttpServletRequest request){
        classTargetService.updateClassTarget(classTargetSaveVo);
        return ReturnResult.success("ok");
    }


    @ApiOperation("业务组主体成本利润统计")
    @RequestMapping(value = "/findMainAccountCostAndIncome",method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<List<MainAccountCostAndIncome>> findMainAccountCostAndIncome(@RequestParam(value = "areaTeamId")Long areaTeamId,@RequestParam(value = "startDate") Date startDate,@RequestParam(value = "endDate") Date endDate, HttpServletRequest request){
        SysUser user = getUser(request);
        endDate=TimeUtils.changeOneDateLastTime(endDate);
        List<MainAccount> mainAccountList = dataStatisticsService.findByAreaTeamId(Arrays.asList(areaTeamId),user.getUserId());


        List<MainAccountCostAndIncome> mainAccountCostAndIncomeList=businessStatisticsService.findMainAccountCostAndIncome(startDate,endDate,mainAccountList);
        return ReturnResult.success(mainAccountCostAndIncomeList);
    }


    @ApiOperation("业务组所有一级成本类型统计")
    @RequestMapping(value = "/findCostByAllCategory",method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<List<CategoryMainAccountVo>> findCostByCategoryIds(@RequestParam(value = "mainAccountId") Long mainAccountId, @RequestParam(value = "startDate") Date startDate,@RequestParam(value = "endDate") Date endDate, HttpServletRequest request){
        endDate=TimeUtils.changeOneDateLastTime(endDate);
        SysUser sysUser=getUser(request);
        List<CategoryMainAccountVo> categoryMainAccountVoList=businessStatisticsService.findCostByAllCategory(mainAccountId,startDate,endDate,sysUser);
        return ReturnResult.success(categoryMainAccountVoList);
    }

    @ApiOperation("业务组单个成本类型详情统计  detailType：0明细，1子类型统计，2课酬统计，3业务组成本统计")
    @RequestMapping(value = "/costDetail",method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<CostDetailVo> costDetail(@RequestParam(value = "detailType",defaultValue = "0") Integer detailType,@RequestParam(value = "mainAccountId") Long mainAccountId,@RequestParam(value = "feeCategoryId") Long feeCategoryId, @RequestParam(value = "startDate") Date startDate,@RequestParam(value = "endDate") Date endDate, HttpServletRequest request){
        endDate=TimeUtils.changeOneDateLastTime(endDate);
        SysUser sysUser=getUser(request);
        CostDetailVo costDetailVo=businessStatisticsService.costDetail(detailType,feeCategoryId,mainAccountId,startDate,endDate,sysUser);
        return ReturnResult.success(costDetailVo);
    }

    @ApiOperation("业务组单个成本类型详情统计  detailType：0明细，1子类型统计，2课酬统计，3业务组成本统计")
    @RequestMapping(value = "/findCostDetail",method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<CostDetailVo> findCostDetail(@RequestParam(value = "detailType",defaultValue = "0") Integer detailType,@RequestParam(value = "mainAccountId") Long mainAccountId,@RequestParam(value = "feeCategoryId") Long feeCategoryId, @RequestParam(value = "startDate") Date startDate,@RequestParam(value = "endDate") Date endDate,@RequestParam(value = "pageNo",defaultValue = "1",required = false)int pageNo,@RequestParam(value = "pageSize",defaultValue = "10",required = false)int pageSize, HttpServletRequest request){
        endDate=TimeUtils.changeOneDateLastTime(endDate);
        SysUser sysUser=getUser(request);
        CostDetailVo costDetailVo=businessStatisticsService.findCostDetail(detailType,feeCategoryId,mainAccountId,startDate,endDate,sysUser,pageNo,pageSize);
        return ReturnResult.success(costDetailVo);
    }

    @ApiOperation("业务组流水明细  detailType :0")
    @RequestMapping(value = "/mainAccountChangeCost",method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<CostDetailVo> mainAccountChangeRecord(@RequestParam(value = "detailType",defaultValue = "0") Integer detailType,@RequestParam(value = "mainAccountId") Long mainAccountId,@RequestParam(value = "feeCategoryId") Long feeCategoryId, @RequestParam(value = "startDate") Date startDate,@RequestParam(value = "endDate") Date endDate,@RequestParam(value = "pageNo")int pageNo,@RequestParam(value = "pageSize")int pageSize, HttpServletRequest request){
        endDate=TimeUtils.changeOneDateLastTime(endDate);
        ChangeRecordQueryVo changeRecordQueryVo=new ChangeRecordQueryVo();
        changeRecordQueryVo.setMainAccountId(mainAccountId);
        changeRecordQueryVo.setDirection(0);
        changeRecordQueryVo.setSubject("cost");
        changeRecordQueryVo.setStartDate(startDate);
        changeRecordQueryVo.setEndDate(endDate);
        changeRecordQueryVo.setCategoryId(feeCategoryId);
        Page<ChangeRecord> changeRecordPage=changeRecordService.findPageByQueryVo(changeRecordQueryVo,pageNo,pageSize);

        return ReturnResult.success(changeRecordPage);
    }

    @ApiOperation("业务组子类成本  detailType :1子类型统计")
    @RequestMapping(value = "/mainAccountCategoryDetail",method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<CostDetailVo> mainAccountCategoryDetail(@RequestParam(value = "detailType",defaultValue = "1") Integer detailType,@RequestParam(value = "mainAccountId") Long mainAccountId,@RequestParam(value = "feeCategoryId") Long feeCategoryId, @RequestParam(value = "startDate") Date startDate,@RequestParam(value = "endDate") Date endDate, HttpServletRequest request){
        endDate=TimeUtils.changeOneDateLastTime(endDate);
        List<CategoryMainAccountVo> categoryMainAccountList = businessStatisticsService.findChildCostByParentId(feeCategoryId, mainAccountId, startDate, endDate);
        return ReturnResult.success(categoryMainAccountList);
    }


    @ApiOperation("业务组课酬明细  detailType :2")
    @RequestMapping(value = "/mainAccountTeacherClassCost",method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Page<TeacherClassCostVo>> mainAccountTeacherClassCost(@RequestParam(value = "detailType",defaultValue = "2") Integer detailType,@RequestParam(value = "mainAccountId") Long mainAccountId,@RequestParam(value = "feeCategoryId") Long feeCategoryId, @RequestParam(value = "startDate") Date startDate,@RequestParam(value = "endDate") Date endDate, @RequestParam(value = "pageNo")int pageNo,@RequestParam(value = "pageSize")int pageSize, HttpServletRequest request){
        endDate=TimeUtils.changeOneDateLastTime(endDate);
        Page<TeacherClassCostVo> teacherClassCostVoPage=businessStatisticsService.classRemunerationPage(mainAccountId,feeCategoryId,startDate,endDate,pageNo,pageSize);
        return ReturnResult.success(teacherClassCostVoPage);
    }

    @ApiOperation("区域业务组明细  detailType :3")
    @RequestMapping(value = "/busTeamCost",method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<List<CategoryMainAccountVo>> busTeamCost(@RequestParam(value = "detailType",defaultValue = "2") Integer detailType,@RequestParam(value = "mainAccountId") Long mainAccountId,@RequestParam(value = "feeCategoryId") Long feeCategoryId, @RequestParam(value = "startDate") Date startDate,@RequestParam(value = "endDate") Date endDate, @RequestParam(value = "pageNo")int pageNo,@RequestParam(value = "pageSize")int pageSize, HttpServletRequest request){
        endDate=TimeUtils.changeOneDateLastTime(endDate);
        SysUser sysUser=this.getUser(request);
        List<CategoryMainAccountVo> categoryMainAccounts = businessStatisticsService.findBusCostByAreaTeam(mainAccountId, startDate, endDate, sysUser);
        return ReturnResult.success(categoryMainAccounts);
    }








    @ApiOperation("业务组收入类型统计")
    @RequestMapping(value = "/findIncomeByAllCategory",method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<List<CategoryMainAccountVo>> findIncomeByCategoryIds(@RequestParam(value = "mainAccountId") Long mainAccountId, @RequestParam(value = "startDate") Date startDate,@RequestParam(value = "endDate") Date endDate, HttpServletRequest request){
        endDate=TimeUtils.changeOneDateLastTime(endDate);
        SysUser sysUser=getUser(request);
        List<CategoryMainAccountVo> categoryMainAccountVoList=businessStatisticsService.findIncomeByAllCategory(mainAccountId,startDate,endDate,sysUser);
        return ReturnResult.success(categoryMainAccountVoList);
    }

    @ApiOperation("业务组单个收入类型详情统计  detailType：6明细,7辅导班，8 业务组营收统计")
    @RequestMapping(value = "/incomeDetail",method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<IncomeDetailVo> incomeDetail(@RequestParam(value = "detailType",defaultValue = "6") Integer detailType,@RequestParam(value = "mainAccountId") Long mainAccountId,@RequestParam(value = "incomeCategoryId") Long incomeCategoryId, @RequestParam(value = "startDate") Date startDate,@RequestParam(value = "endDate") Date endDate, HttpServletRequest request){
        endDate=TimeUtils.changeOneDateLastTime(endDate);
        SysUser sysUser=getUser(request);
        IncomeDetailVo incomeDetailVo=businessStatisticsService.incomeDetail(detailType,incomeCategoryId,mainAccountId,startDate,endDate,sysUser);
        return ReturnResult.success(incomeDetailVo);
    }

    @ApiOperation("业务组单个收入类型详情统计  detailType：6明细,7辅导班，8 业务组营收统计")
    @RequestMapping(value = "/findIncomeDetail",method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<IncomeDetailVo> findIncomeDetail(@RequestParam(value = "detailType",defaultValue = "6") Integer detailType,@RequestParam(value = "mainAccountId") Long mainAccountId,@RequestParam(value = "incomeCategoryId") Long incomeCategoryId, @RequestParam(value = "startDate") Date startDate,@RequestParam(value = "endDate") Date endDate, @RequestParam(value = "pageNo",defaultValue = "1",required = false)int pageNo,@RequestParam(value = "pageSize",defaultValue = "10",required = false)int pageSize,HttpServletRequest request){
        endDate=TimeUtils.changeOneDateLastTime(endDate);
        SysUser sysUser=getUser(request);
        IncomeDetailVo incomeDetailVo=businessStatisticsService.findIncomeDetail(detailType,incomeCategoryId,mainAccountId,startDate,endDate,sysUser,pageNo,pageSize);
        return ReturnResult.success(incomeDetailVo);
    }

    @ApiOperation("业务组收入明细  detailType：6明细")
    @RequestMapping(value = "/mainAccountChangeIncome",method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Page<ChangeRecord>> mainAccountChangeIncome(@RequestParam(value = "detailType",defaultValue = "6") Integer detailType,@RequestParam(value = "mainAccountId") Long mainAccountId,@RequestParam(value = "incomeCategoryId") Long incomeCategoryId, @RequestParam(value = "startDate") Date startDate,@RequestParam(value = "endDate") Date endDate, @RequestParam(value = "pageNo")int pageNo,@RequestParam(value = "pageSize")int pageSize,HttpServletRequest request){
        endDate=TimeUtils.changeOneDateLastTime(endDate);
        ChangeRecordQueryVo changeRecordQueryVo=new ChangeRecordQueryVo();
        changeRecordQueryVo.setMainAccountId(mainAccountId);
        changeRecordQueryVo.setDirection(0);
        changeRecordQueryVo.setSubject("real_income");
        changeRecordQueryVo.setCategoryId(incomeCategoryId);
        changeRecordQueryVo.setStartDate(startDate);
        changeRecordQueryVo.setEndDate(endDate);
        Page<ChangeRecord> changeRecordPage=changeRecordService.findPageByQueryVo(changeRecordQueryVo,pageNo,pageSize);
        return ReturnResult.success(changeRecordPage);
    }

    @ApiOperation("业务组课程收入  detailType：7班级收入")
    @RequestMapping(value = "/mainAccountClassIncome",method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Page<ClassIncomeVo>> mainAccountClassIncome(@RequestParam(value = "detailType",defaultValue = "6") Integer detailType,@RequestParam(value = "mainAccountId") Long mainAccountId,@RequestParam(value = "incomeCategoryId") Long incomeCategoryId, @RequestParam(value = "startDate") Date startDate,@RequestParam(value = "endDate") Date endDate, @RequestParam(value = "pageNo")int pageNo,@RequestParam(value = "pageSize")int pageSize,HttpServletRequest request){
        endDate=TimeUtils.changeOneDateLastTime(endDate);
        Page<ClassIncomeVo> classIncomeVoPage=businessStatisticsService.classIncomePage(Arrays.asList(mainAccountId),startDate,endDate,pageNo,pageSize);
        return ReturnResult.success(classIncomeVoPage);
    }

    @ApiOperation("区域业务组收入  detailType：8业务组营收统计")
    @RequestMapping(value = "/busTeamIncome",method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<List<CategoryMainAccountVo>> busTeamIncome(@RequestParam(value = "detailType",defaultValue = "6") Integer detailType,@RequestParam(value = "mainAccountId") Long mainAccountId,@RequestParam(value = "incomeCategoryId") Long incomeCategoryId, @RequestParam(value = "startDate") Date startDate,@RequestParam(value = "endDate") Date endDate, @RequestParam(value = "pageNo")int pageNo,@RequestParam(value = "pageSize")int pageSize,HttpServletRequest request){
        endDate=TimeUtils.changeOneDateLastTime(endDate);
        SysUser sysUser=getUser(request);
        List<CategoryMainAccountVo> categoryMainAccountVoList = businessStatisticsService.findBusIncomeByArea(mainAccountId, startDate, endDate, sysUser);
        return ReturnResult.success(categoryMainAccountVoList);
    }


    @ApiOperation("获得产品线统计列表")
    @RequestMapping(value = "/productStatisticsList",method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<List<ProductCostAndIncomeVo>> productStatisticsList(@RequestParam(value = "areaTeamId")Long areaTeamId,@RequestParam(value = "startDate")Date startDate,@RequestParam(value = "endDate")Date endDate, HttpServletRequest request){
        endDate=TimeUtils.changeOneDateLastTime(endDate);
        SysUser sysUser=this.getUser(request);
        List<Product> productList=productService.findBaseProductByAreaTeamId(areaTeamId);
        List<ProductCostAndIncomeVo> productCostAndIncomeVoList=productStatisticsService.findProductCostAndIncome(Arrays.asList(areaTeamId),startDate,endDate,productList,sysUser);
        return ReturnResult.success(productCostAndIncomeVoList);
    }

    @ApiOperation("获得单条产品线成本类型统计")
    @RequestMapping(value = "/productStatisticsByCategory",method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<List<ProductCostByCategoryVo>> productStatisticsByCategory(@RequestParam(value = "productId") Long productId,@RequestParam(value = "startDate")Date startDate,@RequestParam(value = "endDate")Date endDate, HttpServletRequest request){
        endDate=TimeUtils.changeOneDateLastTime(endDate);
        SysUser sysUser=this.getUser(request);
        String mainAccountFeeCategory = siteConfigService.getConfigValueFromCache("product_feeCategory");
        List<FeeCategoryTreeMapVo> allFeeCategoryTreeMapVoList = JSONArray.parseArray(mainAccountFeeCategory, FeeCategoryTreeMapVo.class);
        List<ProductCostByCategoryVo> productCostByCategoryVoList=productStatisticsService.findProductCategoryCostByProductId(allFeeCategoryTreeMapVoList,productId,startDate,endDate,sysUser);
        return ReturnResult.success(productCostByCategoryVoList);
    }

    @ApiOperation("获得单条产品营收")
    @RequestMapping(value = "/productIncomeList",method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<List<ClassIncomeVo>> productIncomeList(@RequestParam(value = "productId") Long productId,@RequestParam(value = "startDate")Date startDate,@RequestParam(value = "endDate")Date endDate, HttpServletRequest request){
        endDate=TimeUtils.changeOneDateLastTime(endDate);
        SysUser sysUser=this.getUser(request);
        List<ClassIncomeVo> productIncomeList=productStatisticsService.findClassIncomeByProductId(productId,startDate,endDate,sysUser);
        return ReturnResult.success(productIncomeList);
    }

    @ApiOperation("获得单条产品营收")
    @RequestMapping(value = "/productIncomePage",method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Page<ClassIncomeVo>> productIncomePage(@RequestParam(value = "productId") Long productId,@RequestParam(value = "startDate")Date startDate,@RequestParam(value = "endDate")Date endDate,@RequestParam(value = "pageNo")int pageNo,@RequestParam(value = "pageSize")int pageSize, HttpServletRequest request){
        endDate=TimeUtils.changeOneDateLastTime(endDate);
        SysUser sysUser=this.getUser(request);
        Page<ClassIncomeVo> productIncomeList=productStatisticsService.findClassIncomePageByProductId(productId,startDate,endDate,sysUser,pageNo,pageSize);
        return ReturnResult.success(productIncomeList);
    }



    @ApiOperation("产品线点击明细  detailType 1子成本统计，2课酬")
    @RequestMapping(value = "/productCostDetail",method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<List<ProductCostDetailVo>> productCostDetail(@RequestParam(value = "detailType")Integer detailType,@RequestParam(value = "feeCategoryId") Long feeCategoryId, @RequestParam(value = "productId") Long productId,@RequestParam(value = "startDate")Date startDate,@RequestParam(value = "endDate")Date endDate, HttpServletRequest request){
        endDate=TimeUtils.changeOneDateLastTime(endDate);
        SysUser sysUser=this.getUser(request);
        ProductCostDetailVo productCostDetailVo=productStatisticsService.findCostDetailByDetailType(detailType,feeCategoryId,productId,startDate,endDate,sysUser);
        return ReturnResult.success(productCostDetailVo);
    }


    @ApiOperation("产品线点击明细  detailType 1子成本统计，2课酬")
    @RequestMapping(value = "/findProductCostDetail",method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<List<ProductCostDetailVo>> findProductCostDetail(@RequestParam(value = "detailType")Integer detailType,@RequestParam(value = "feeCategoryId") Long feeCategoryId, @RequestParam(value = "productId") Long productId,@RequestParam(value = "startDate")Date startDate,@RequestParam(value = "endDate")Date endDate,@RequestParam(value = "pageNo",defaultValue = "1",required = false)int pageNo,@RequestParam(value = "pageSize",defaultValue = "10",required = false)int pageSize, HttpServletRequest request){
        endDate=TimeUtils.changeOneDateLastTime(endDate);
        SysUser sysUser=this.getUser(request);
        ProductCostDetailVo productCostDetailVo=productStatisticsService.findProductCostDetail(detailType,feeCategoryId,productId,startDate,endDate,sysUser,pageNo,pageSize);
        return ReturnResult.success(productCostDetailVo);
    }
    @ApiOperation("产品线子成本 detailType 1子成本统计")
    @RequestMapping(value = "/productCategoryDetail",method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<List<ProductCostByCategoryVo>> productCategoryDetail(@RequestParam(value = "detailType")Integer detailType,@RequestParam(value = "feeCategoryId") Long feeCategoryId, @RequestParam(value = "productId") Long productId,@RequestParam(value = "startDate")Date startDate,@RequestParam(value = "endDate")Date endDate, HttpServletRequest request){
        endDate=TimeUtils.changeOneDateLastTime(endDate);
        SysUser sysUser=this.getUser(request);
        String mainAccountFeeCategory = siteConfigService.getConfigValueFromCache("product_feeCategory");
        List<FeeCategoryTreeMapVo> allFeeCategoryTreeMapVoList = JSONArray.parseArray(mainAccountFeeCategory, FeeCategoryTreeMapVo.class);
        List<FeeCategoryTreeMapVo> feeCategoryTreeMapVoList=businessStatisticsService.findChildListByParentId(allFeeCategoryTreeMapVoList,feeCategoryId);
        List<ProductCostByCategoryVo> productCostByCategoryVoList=productStatisticsService.findProductCategoryCostByProductId(feeCategoryTreeMapVoList,productId,startDate,endDate,sysUser);
        return ReturnResult.success(productCostByCategoryVoList);
    }

    @ApiOperation("产品线课酬 detailType 2课酬 ")
    @RequestMapping(value = "/productTeacherClassCost",method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Page<TeacherClassCostVo>> productTeacherClassCost(@RequestParam(value = "detailType")Integer detailType,@RequestParam(value = "feeCategoryId") Long feeCategoryId, @RequestParam(value = "productId") Long productId,@RequestParam(value = "startDate")Date startDate,@RequestParam(value = "endDate")Date endDate,@RequestParam(value = "pageNo")int pageNo,@RequestParam(value = "pageSize")int pageSize, HttpServletRequest request){
        endDate=TimeUtils.changeOneDateLastTime(endDate);
        SysUser sysUser=this.getUser(request);
        Page<TeacherClassCostVo> teacherClassCostVoPage=productStatisticsService.productClassRemunerationPage(productId,feeCategoryId,startDate,endDate,sysUser,pageNo,pageSize);
        return ReturnResult.success(teacherClassCostVoPage);
    }





    @ApiOperation("区域年级科目统计")
    @RequestMapping(value = "/areaTeamGradeAndSubjectStatistics",method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<List<GradeAndSubjectCostAndIncomeVo>> areaTeamGradeAndSubjectStatistics(@RequestParam(value = "gradeId",required = false)String gradeId,@RequestParam(value = "subjectId",required = false)String subjectId,  @RequestParam(value = "areaTeamId")long areaTeamId , @RequestParam(value = "startDate")Date startDate,@RequestParam(value = "endDate")Date endDate, HttpServletRequest request){
        endDate=TimeUtils.changeOneDateLastTime(endDate);
        SysUser sysUser=this.getUser(request);
        List<GradeAndSubjectCostAndIncomeVo> gradeAndSubjectCostAndIncomeVoList=gradeAndSubjectStatisticsService.findCostAndIncomeList(areaTeamId,startDate,endDate,Utils.toLongIds(gradeId),Utils.toLongIds(subjectId),sysUser);
        return ReturnResult.success(gradeAndSubjectCostAndIncomeVoList);
    }

    @ApiOperation("单个年级科目详情")
    @RequestMapping(value = "/gradeAndSubjectAllCategoryDetail",method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<List<GradeAndSubjectCostByCategoryVo>> gradeAndSubjectAllCategoryDetail(@RequestParam(value = "areaTeamId")Long areaTeamId,@RequestParam(value = "gradeId")String gradeId,@RequestParam(value = "subjectId")String subjectId, @RequestParam(value = "startDate")Date startDate,@RequestParam(value = "endDate")Date endDate, HttpServletRequest request){
        endDate=TimeUtils.changeOneDateLastTime(endDate);
        SysUser sysUser=this.getUser(request);
        String mainAccountFeeCategory = siteConfigService.getConfigValueFromCache("grade_subject_feeCategory");
        List<FeeCategoryTreeMapVo> allFeeCategoryTreeMapVoList = JSONArray.parseArray(mainAccountFeeCategory, FeeCategoryTreeMapVo.class);
        List<GradeAndSubjectCostByCategoryVo> gradeAndSubjectCostByCategoryVoList=gradeAndSubjectStatisticsService.findCategoryCostByGradeAndSubject(areaTeamId,allFeeCategoryTreeMapVoList,Utils.toLongIds(gradeId),Utils.toLongIds(subjectId),startDate,endDate,sysUser);
        return ReturnResult.success(gradeAndSubjectCostByCategoryVoList);
    }

    @ApiOperation("单个年级科目明细")
    @RequestMapping(value = "/gradeAndSubjectDetail",method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<List<GradeAndSubjectCostDetailVo>> gradeAndSubjectDetail(@RequestParam(value = "feeCategoryId")Long feeCategoryId,@RequestParam(value = "detailType")Integer detailType,@RequestParam(value = "areaTeamId")Long areaTeamId, @RequestParam(value = "gradeId")Long gradeId, @RequestParam(value = "subjectId")Long subjectId, @RequestParam(value = "startDate")Date startDate, @RequestParam(value = "endDate")Date endDate, HttpServletRequest request){
        endDate=TimeUtils.changeOneDateLastTime(endDate);
        SysUser sysUser=this.getUser(request);
        GradeAndSubjectCostDetailVo gradeAndSubjectCostDetailVo=gradeAndSubjectStatisticsService.findDetail(areaTeamId,detailType,feeCategoryId,gradeId,subjectId,startDate,endDate,sysUser);
        return ReturnResult.success(gradeAndSubjectCostDetailVo);
    }


    @ApiOperation("单个年级科目子类型 detailType：1")
    @RequestMapping(value = "/gradeSubjectCategoryDetail",method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<List<GradeAndSubjectCostDetailVo>> gradeSubjectCategoryDetail(@RequestParam(value = "feeCategoryId")Long feeCategoryId,@RequestParam(value = "detailType")Integer detailType,@RequestParam(value = "areaTeamId")Long areaTeamId, @RequestParam(value = "gradeId")String gradeId, @RequestParam(value = "subjectId")String subjectId, @RequestParam(value = "startDate")Date startDate, @RequestParam(value = "endDate")Date endDate, HttpServletRequest request){
        endDate=TimeUtils.changeOneDateLastTime(endDate);
        SysUser sysUser=this.getUser(request);
        String mainAccountFeeCategory = siteConfigService.getConfigValueFromCache("grade_subject_feeCategory");
        List<FeeCategoryTreeMapVo> allFeeCategoryTreeMapVoList = JSONArray.parseArray(mainAccountFeeCategory, FeeCategoryTreeMapVo.class);
        List<FeeCategoryTreeMapVo> feeCategoryTreeMapVoList=businessStatisticsService.findChildListByParentId(allFeeCategoryTreeMapVoList,feeCategoryId);
        List<GradeAndSubjectCostByCategoryVo> gradeAndSubjectCostByCategoryVoList=gradeAndSubjectStatisticsService.findCategoryCostByGradeAndSubject(areaTeamId,feeCategoryTreeMapVoList,Utils.toLongIds(gradeId),Utils.toLongIds(subjectId),startDate,endDate,sysUser);
        return ReturnResult.success(gradeAndSubjectCostByCategoryVoList);
    }


    @ApiOperation("单个年级科目课酬 detailType：2")
    @RequestMapping(value = "/gradeSubjectTeacherClassCost",method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Page<TeacherClassCostVo> > gradeSubjectTeacherClassCost(@RequestParam(value = "feeCategoryId")Long feeCategoryId,@RequestParam(value = "detailType")Integer detailType,@RequestParam(value = "areaTeamId")Long areaTeamId, @RequestParam(value = "gradeId")Long gradeId, @RequestParam(value = "subjectId")Long subjectId, @RequestParam(value = "startDate")Date startDate, @RequestParam(value = "endDate")Date endDate,@RequestParam(value = "pageNo")int pageNo,@RequestParam(value = "pageSize")int pageSize, HttpServletRequest request){
        endDate=TimeUtils.changeOneDateLastTime(endDate);
        SysUser sysUser=this.getUser(request);
        Page<TeacherClassCostVo> teacherClassCostVoPage=gradeAndSubjectStatisticsService.gradeAndSubjectClassRemunerationPage(areaTeamId,gradeId,subjectId,feeCategoryId,startDate,endDate,sysUser,pageNo,pageSize);
        return ReturnResult.success(teacherClassCostVoPage);
    }




    @ApiOperation("单个年级科目营收")
    @RequestMapping(value = "/gradeAndSubjectIncome",method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<List<GradeAndSubjectCostDetailVo>> gradeAndSubjectIncome(@RequestParam(value = "areaTeamId")Long areaTeamId, @RequestParam(value = "gradeId")Long gradeId, @RequestParam(value = "subjectId")Long subjectId, @RequestParam(value = "startDate")Date startDate, @RequestParam(value = "endDate")Date endDate, HttpServletRequest request){
        endDate=TimeUtils.changeOneDateLastTime(endDate);
        SysUser sysUser=this.getUser(request);
        List<ClassIncomeVo> gradeAndSubjectIncomeList=gradeAndSubjectStatisticsService.findClassIncomeByAreaTeamId(areaTeamId,gradeId,subjectId,startDate,endDate,sysUser);
        return ReturnResult.success(gradeAndSubjectIncomeList);
    }


    @ApiOperation("单个年级科目营收")
    @RequestMapping(value = "/gradeSubjectIncome",method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Page<GradeAndSubjectCostDetailVo>> gradeSubjectIncome(@RequestParam(value = "areaTeamId")Long areaTeamId, @RequestParam(value = "gradeId")Long gradeId, @RequestParam(value = "subjectId")Long subjectId, @RequestParam(value = "startDate")Date startDate, @RequestParam(value = "endDate")Date endDate,@RequestParam(value = "pageNo")int pageNo,@RequestParam(value = "pageSize")int pageSize, HttpServletRequest request){
        endDate=TimeUtils.changeOneDateLastTime(endDate);
        SysUser sysUser=this.getUser(request);
        Page<ClassIncomeVo> classIncomeVoPage=gradeAndSubjectStatisticsService.findClassIncomePageByAreaTeamId(areaTeamId,Arrays.asList(gradeId),Arrays.asList(subjectId),startDate,endDate,sysUser,pageNo,pageSize);
        return ReturnResult.success(classIncomeVoPage);
    }



    @ApiOperation("区域下业务组产品营收利润")
    @RequestMapping(value = "/incomeProfitsOfAreaTeam",method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<IncomeProfitsVo> incomeProfitsOfAreaTeam(@RequestParam(value = "areaTeamId")Long areaTeamId,@RequestParam(value = "date")String date,  HttpServletRequest request){
        Date startDate= TimeUtils.firstDateOfMonth(Utils.parseDate(date,"yyyy-MM"));
        Date endDate=TimeUtils.lastDateOfMonth(Utils.parseDate(date,"yyyy-MM"));
        endDate=TimeUtils.changeOneDateLastTime(endDate);
        IncomeProfitsVo incomeProfitsVo=new IncomeProfitsVo();
        SysUser sysUser=this.getUser(request);
        incomeProfitsVo.setProductTeamMap(dataStatisticsService.findProductByAreaTeamId(areaTeamId,startDate,endDate,sysUser));
        incomeProfitsVo.setBusTeamMap(dataStatisticsService.findBusTeamByAreaTeamId(areaTeamId,startDate,endDate));
        return ReturnResult.success(incomeProfitsVo);
    }








    @ApiOperation("区域下业务组产品近期经营情况")
    @RequestMapping(value = "/businessCaseOfAreaTeam",method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<BusinessCaseVo> businessCaseOfAreaTeam(@RequestParam(value = "areaTeamId")Long areaTeamId, @RequestParam(value = "monthNum")int monthNum,  HttpServletRequest request) throws InterruptedException, ExecutionException {
        BusinessCaseVo businessCaseVo=new BusinessCaseVo();
        SysUser sysUser=this.getUser(request);
        businessCaseVo.setBusCase(dataStatisticsService.findBusTeamRecentDetail(areaTeamId,TimeUtils.now(),monthNum));
        businessCaseVo.setProdcutCase(dataStatisticsService.findProdcutRecentDetail(areaTeamId,TimeUtils.now(),monthNum,sysUser));
        return ReturnResult.success(businessCaseVo);
    }





    @ApiOperation("区域下财务预警")
    @RequestMapping(value = "/warningOfAreaTeam",method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<WarningVo> warningOfAreaTeam(@RequestParam(value = "areaTeamId")Long areaTeamId, @RequestParam(value = "periodId")Long periodId,  HttpServletRequest request){
        WarningVo warningVo=new WarningVo();
        SysUser sysUser=this.getUser(request);
        warningVo.setProductCostAndIncomeVoList(dataStatisticsService.findProductTargetAndReal(areaTeamId,periodId,sysUser));
        warningVo.setMainAccountCostAndIncomeList(dataStatisticsService.findBusTeamTargetAndReal(areaTeamId,periodId));
        return ReturnResult.success(warningVo);
    }


    @ApiOperation("满班率")
    @RequestMapping(value = "/fullClassRate",method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Map<String,List<FullClassRate>>> fullClassRate(@RequestParam(value = "areaTeamId")Long areaTeamId, @RequestParam(value = "periodId")Long periodId,  HttpServletRequest request){
        SysUser sysUser=this.getUser(request);
        Map<String,List<FullClassRate>> resultMap=dataStatisticsService.findFullRate(areaTeamId,periodId,sysUser.getUserId());
        return ReturnResult.success(resultMap);
    }

    @ApiOperation("业务组满班率")
    @RequestMapping(value = "/busTeamfullClassRate",method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<List<BusTeamFullClassRate>> BusTeamfullClassRate(@RequestParam(value = "areaTeamId")Long areaTeamId,@RequestParam(value = "busTeamIds",required = false)String busTeamIds, @RequestParam(value = "periodIds",required = true)String periodIds,@RequestParam(value = "gradeIds",required = false)String gradeIds, @RequestParam(value = "subjectIds",required = false)String subjectIds,  HttpServletRequest request){
        List<Long> busTeamIdList=Utils.toLongIds(busTeamIds);
        if (busTeamIdList.size()<=0){
            busTeamIdList=dataStatisticsService.findPermissionBusTeam(Arrays.asList(areaTeamId),this.getUserId(request));
        }
        List<BusTeamFullClassRate> busTeamFullClassRateList=dataStatisticsService.findBusTeamFullClassRate(busTeamIdList,Utils.toLongIds(periodIds),Utils.toLongIds(gradeIds),Utils.toLongIds(subjectIds),areaTeamId);
        return ReturnResult.success(busTeamFullClassRateList);
    }

    @ApiOperation("导出业务组满班率")
    @RequestMapping(value = "/exportBusTeamFullClassRate",method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Page<CounselorBranchBonusVo>> exportBusTeamFullClassRate(@RequestParam(value = "areaTeamId")Long areaTeamId,@RequestParam(value = "busTeamIds",required = false)String busTeamIds, @RequestParam(value = "periodIds",required = true)String periodIds, @RequestParam(value = "gradeIds",required = false)String gradeIds, HttpServletRequest request,HttpServletResponse response)throws  IOException{
        List<Long> busTeamIdList=Utils.toLongIds(busTeamIds);
        if (busTeamIdList.size()<=0){
            busTeamIdList=dataStatisticsService.findPermissionBusTeam(Arrays.asList(areaTeamId),this.getUserId(request));
        }
        Webs.writeExcel(request,response,dataStatisticsService.exportBusTeamFullClassRate(busTeamIdList,Utils.toLongIds(periodIds),Utils.toLongIds(gradeIds),areaTeamId) ,"业务组满班率");
        return ReturnResult.success("ok");
    }


    @ApiOperation("班均")
    @RequestMapping(value = "/findClassAvgReg",method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Page<ClassAvgRegVo>> findClassAvgReg(@ModelAttribute SimpleQueryVo simpleQueryVo,@RequestParam("pageNo") int pageNo,@RequestParam("pageSize") int pageSize, HttpServletRequest request){
        DataPermission dataPermission=this.getDataPermission(request);
        Page<ClassAvgRegVo> page=dataStatisticsService.findClassAvgReg(dataPermission,simpleQueryVo,pageNo,pageSize);
        return ReturnResult.success(page);
    }

    @ApiOperation("导出班均")
    @RequestMapping(value = "/exportClassAvgReg",method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Page<CounselorBranchBonusVo>> exportClassAvgReg(@ModelAttribute SimpleQueryVo simpleQueryVo,HttpServletRequest request,HttpServletResponse response)throws  IOException{
        DataPermission dataPermission=this.getDataPermission(request);
        Webs.writeExcel(request,response,dataStatisticsService.exportClassAvgReg(dataPermission,simpleQueryVo) ,"班均");
        return ReturnResult.success("ok");
    }

    //分割线
    @ApiOperation("咨询师科数统计（奖金指标）")
    @RequestMapping(value = "/findCounselorBranchBonusPage",method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Page<CounselorBranchBonusVo>> findCounselorBranchBonusPage(@RequestParam(value = "gradeIds",required = false)String gradeIds,
                                                                                   @RequestParam(value = "busTeamIds",required = false)String busTeamIds,
                                                                                   @RequestParam(value = "periodIds")String periodIds,
                                                                                   @RequestParam(value = "bigLectureNum",defaultValue = "5")Integer bigLectureNum,
                                                                                   @ModelAttribute TeacherQueryVo teacherQueryVo,
                                                                                   @RequestParam(value = "startDate",required = false) Date startDate,
                                                                                   @RequestParam(value = "endDate",required = false) Date endDate,
                                                                                   @RequestParam(value = "startPayTime",required = false)Date startPayTime,
                                                                                   @RequestParam(value = "endPayTime",required = false)Date endPayTime,
                                                                                   @RequestParam(value = "pageNo") int pageNo, @RequestParam(value = "pageSize") int pageSize, HttpServletRequest request){
        DataPermission dataPermission = getDataPermission(request);
        if (teacherQueryVo.getAreaTeamId()==null){
            throw new BusException("区域必选");
        }
        if (teacherQueryVo.getAccessType()==null){
            teacherQueryVo.setAccessTypes(Arrays.asList(1,2));
        }
        PeriodQueryRegVo periodQueryRegVo=new PeriodQueryRegVo();
        periodQueryRegVo.setStartDate(startDate);
        if (endDate!=null){
            periodQueryRegVo.setEndDate(TimeUtils.changeOneDateLastTime(endDate));
        }
        periodQueryRegVo.setStartPayTime(startPayTime);
        if (endPayTime!=null){
            periodQueryRegVo.setEndPayTime(TimeUtils.changeOneDateLastTime(endPayTime));
        }
        List<Long> busTeamIdList=Utils.toLongIds(busTeamIds);


        periodQueryRegVo.setRegStatus(0);
        periodQueryRegVo.setChargingStatus(2);
        if (StringUtils.isNotEmpty(gradeIds)){
            periodQueryRegVo.setGradeIds(Utils.toLongIds(gradeIds));
        }

        Page<CounselorBranchBonusVo> page=indexStatisticsService.findCounselorBranchBonusPage(busTeamIdList, periodQueryRegVo, dataPermission, teacherQueryVo,Utils.toLongIds(periodIds),  pageNo,  pageSize,  bigLectureNum);
        return ReturnResult.success(page);
    }

    @ApiOperation("导出咨询师科数统计（奖金指标）")
    @RequestMapping(value = "/exportCounselorBranchBonus",method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Page<CounselorBranchBonusVo>> exportCounselorBranchBonus(@RequestParam(value = "gradeIds",required = false)String gradeIds,
                                                                                 @RequestParam(value = "busTeamIds",required = false)String busTeamIds,
                                                                                 @RequestParam(value = "periodIds")String periodIds,
                                                                                 @RequestParam(value = "bigLectureNum",defaultValue = "5")Integer bigLectureNum,
                                                                                 @ModelAttribute TeacherQueryVo teacherQueryVo,
                                                                                 @RequestParam(value = "startDate",required = false) Date startDate,
                                                                                 @RequestParam(value = "endDate",required = false) Date endDate,
                                                                                 @RequestParam(value = "startPayTime",required = false)Date startPayTime,
                                                                                 @RequestParam(value = "endPayTime",required = false)Date endPayTime,
                                                                                 HttpServletRequest request,HttpServletResponse response)throws  IOException{
        if (teacherQueryVo.getAreaTeamId()==null){
            throw new BusException("区域必选");
        }
        if (teacherQueryVo.getAccessType()==null){
            teacherQueryVo.setAccessTypes(Arrays.asList(1,2));
        }
        PeriodQueryRegVo periodQueryRegVo=new PeriodQueryRegVo();
        periodQueryRegVo.setStartDate(startDate);
        if (endDate!=null){
            periodQueryRegVo.setEndDate(TimeUtils.changeOneDateLastTime(endDate));
        }
        periodQueryRegVo.setStartPayTime(startPayTime);
        if (endPayTime!=null){
            periodQueryRegVo.setEndPayTime(TimeUtils.changeOneDateLastTime(endPayTime));
        }
        List<Long> busTeamIdList=Utils.toLongIds(busTeamIds);

        periodQueryRegVo.setRegStatus(0);
        periodQueryRegVo.setChargingStatus(2);
        if (StringUtils.isNotEmpty(gradeIds)){
            periodQueryRegVo.setGradeIds(Utils.toLongIds(gradeIds));
        }

        Webs.writeExcel(request,response,indexStatisticsService.exportCounselorBranchBonus(busTeamIdList, periodQueryRegVo, getDataPermission(request), teacherQueryVo,Utils.toLongIds(periodIds),  bigLectureNum) ,"咨询师科数统计（奖金指标）");
        return ReturnResult.success("ok");
    }


    @ApiOperation("班主任续读科数的统计，基于生源类型")
    @RequestMapping(value = "/findSeniorBranchBonusPage",method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Page<SeniorBranchBonusVo>> findSeniorBranchBonusPage(@RequestParam(value = "busTeamIds",required = false)String busTeamIds,@RequestParam(value = "periodIds")String periodIds,@RequestParam(value = "bigLectureNum",defaultValue = "5")Integer bigLectureNum,@ModelAttribute TeacherQueryVo teacherQueryVo,@ModelAttribute RegRelativceQueryVo regRelativceQueryVo,@RequestParam(value = "teacherType",defaultValue = "seniorId")String teacherType, @RequestParam(value = "pageNo") int pageNo, @RequestParam(value = "pageSize") int pageSize, HttpServletRequest request){
        DataPermission dataPermission = getDataPermission(request);
        if (teacherQueryVo.getAreaTeamId()==null){
            throw new BusException("区域必选");
        }
        teacherQueryVo.setAccessType(1);
        regRelativceQueryVo.setRecordChargingStatus(2);
        if (regRelativceQueryVo.getEndRecordRegTime()!=null){
            regRelativceQueryVo.setEndRecordRegTime(TimeUtils.changeOneDateLastTime(regRelativceQueryVo.getEndRecordRegTime()));
        }
        if (regRelativceQueryVo.getEndPayTime()!=null){
            regRelativceQueryVo.setEndPayTime(TimeUtils.changeOneDateLastTime(regRelativceQueryVo.getEndPayTime()));
        }
        List<Long> busTeamIdList=Utils.toLongIds(busTeamIds);
        if (busTeamIdList.size()<=0){
            busTeamIdList=dataStatisticsService.findPermissionBusTeam(Arrays.asList(teacherQueryVo.getAreaTeamId()),this.getUserId(request));
        }


        Page<SeniorBranchBonusVo> page=indexStatisticsService.findSeniorBranchBonusPage(busTeamIdList, regRelativceQueryVo, dataPermission, teacherQueryVo,Utils.toLongIds(periodIds),  pageNo,  pageSize,  bigLectureNum);
        return ReturnResult.success(page);
    }

    @ApiOperation("导出班主任续读科数的统计，基于生源类型")
    @RequestMapping(value = "/exportSeniorBranchBonus",method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Page<ClassComletionRateVo>> exportSeniorBranchBonus(@RequestParam(value = "busTeamIds",required = false)String busTeamIds,@RequestParam(value = "periodIds")String periodIds,@RequestParam(value = "bigLectureNum",defaultValue = "5")Integer bigLectureNum,@ModelAttribute TeacherQueryVo teacherQueryVo,@ModelAttribute RegRelativceQueryVo regRelativceQueryVo,@RequestParam(value = "teacherType",defaultValue = "seniorId")String teacherType,HttpServletRequest request,HttpServletResponse response)throws  IOException{
        if (teacherQueryVo.getAreaTeamId()==null){
            throw new BusException("区域必选");
        }
        teacherQueryVo.setAccessType(1);
        regRelativceQueryVo.setRecordChargingStatus(2);
        if (regRelativceQueryVo.getEndRecordRegTime()!=null){
            regRelativceQueryVo.setEndRecordRegTime(TimeUtils.changeOneDateLastTime(regRelativceQueryVo.getEndRecordRegTime()));
        }
        if (regRelativceQueryVo.getEndPayTime()!=null){
            regRelativceQueryVo.setEndPayTime(TimeUtils.changeOneDateLastTime(regRelativceQueryVo.getEndPayTime()));
        }
        List<Long> busTeamIdList=Utils.toLongIds(busTeamIds);
        if (busTeamIdList.size()<=0){
            busTeamIdList=dataStatisticsService.findPermissionBusTeam(Arrays.asList(teacherQueryVo.getAreaTeamId()),this.getUserId(request));
        }

        Webs.writeExcel(request,response,indexStatisticsService.exportSeniorBranchBonus(busTeamIdList,Arrays.asList(2,3),teacherType, regRelativceQueryVo, getDataPermission(request), teacherQueryVo,Utils.toLongIds(periodIds),   bigLectureNum) ,"班主任续读统计（奖金指标）");
        return ReturnResult.success("ok");
    }


    @ApiOperation("教师续读统计（奖金指标）")
    @RequestMapping(value = "/findClassComletionRateVoPage", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Page<ClassComletionRateVo>> findClassComletionRateVoPage(@RequestParam(value = "periodIds") String periodIds,@RequestParam("busTeamIds")String busTeamIds,@RequestParam("gradeIds")String gradeIds, @ModelAttribute CourseClassQueryVo courseClassQueryVo, @ModelAttribute RegRelativceQueryVo regRelativceQueryVo,  @RequestParam(value = "pageNo") int pageNo, @RequestParam(value = "pageSize") int pageSize, HttpServletRequest request) {
        DataPermission dataPermission = getDataPermission(request);

        Page<ClassComletionRateVo> page = indexStatisticsService.findClassComletionRateVoPage(Utils.toLongIds(periodIds),Utils.toLongIds(busTeamIds),Utils.toLongIds(gradeIds), courseClassQueryVo,  dataPermission, pageNo, pageSize,  regRelativceQueryVo);
        return ReturnResult.success(page);
    }

    @ApiOperation("导出教师续读统计（奖金指标）")
    @RequestMapping(value = "/exportClassComletionRate",method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Page<ClassComletionRateVo>> exportClassComletionRate(@RequestParam(value = "periodIds") String periodIds,@RequestParam("busTeamIds")String busTeamIds,@RequestParam("gradeIds")String gradeIds, @ModelAttribute CourseClassQueryVo courseClassQueryVo, @ModelAttribute RegRelativceQueryVo regRelativceQueryVo, HttpServletRequest request, HttpServletResponse response) throws IOException {
        DataPermission dataPermission = getDataPermission(request);
        Webs.writeExcel(request, response, indexStatisticsService.exportClassComletionRate(Utils.toLongIds(periodIds),Utils.toLongIds(busTeamIds),Utils.toLongIds(gradeIds), courseClassQueryVo,  dataPermission,  regRelativceQueryVo, Arrays.asList(4, 5)), "教师续读统计（奖金指标）");
        return ReturnResult.success("ok");
    }

    @ApiOperation("教师任教情况统计（奖金指标）")
    @RequestMapping(value = "/findClassLectureGroupDetail", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Page<ClassLectureGroupDetailVo>> findClassLectureGroupDetail(@RequestParam(value = "periodIds") String periodIds, @RequestParam("busTeamIds")String busTeamIds, @RequestParam("gradeIds")String gradeIds, @ModelAttribute ClassLectureDetailQueryVo classLectureDetailQueryVo, @RequestParam("pageNo")int pageNo,@RequestParam("pageSize")int pageSize, HttpServletRequest request) {

        DataPermission dataPermission=this.getDataPermission(request);
        Page<ClassLectureGroupDetailVo> page = indexStatisticsService.findClassLectureGroupDetail(dataPermission,Utils.toLongIds(busTeamIds),Utils.toLongIds(periodIds),Utils.toLongIds(gradeIds), classLectureDetailQueryVo,pageNo,pageSize);
        return ReturnResult.success(page);
    }

    @ApiOperation("导出教师任教情况统计（奖金指标）")
    @RequestMapping(value = "/exportClassLectureGroupDetail",method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Page<ClassLectureGroupDetailVo>> exportClassLectureGroupDetail(@RequestParam(value = "periodIds") String periodIds, @RequestParam("busTeamIds")String busTeamIds, @RequestParam("gradeIds")String gradeIds, @ModelAttribute ClassLectureDetailQueryVo classLectureDetailQueryVo, HttpServletRequest request, HttpServletResponse response) throws IOException {
        DataPermission dataPermission=this.getDataPermission(request);
        Webs.writeExcel(request, response, indexStatisticsService.exportClassLectureGroupDetail(dataPermission,Utils.toLongIds(busTeamIds),Utils.toLongIds(periodIds),Utils.toLongIds(gradeIds), classLectureDetailQueryVo), "教师任教情况统计（奖金指标）");
        return ReturnResult.success("ok");
    }



    @ApiOperation("校区续读统计（营运指标）")
    @RequestMapping(value = "/findGradeCompletionVoList", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Page<GradeCompletionRateVo>> findGradeCompletionVoList(@RequestParam("areaTeamId") Long areaTeamId,@RequestParam(value = "periodIds") String periodIds, @RequestParam("busTeamIds")String busTeamIds, @RequestParam("gradeIds")String gradeIds,HttpServletRequest request) {

        //List<GradeCompletionRateVo> list = indexStatisticsService.findGradeCompletionVoList(regRelativceQueryVo,Arrays.asList(0,1,4,5),Utils.toLongIds(busTeamIds),Utils.toLongIds(periodIds),Utils.toLongIds(gradeIds));
        List<GradeCompletionRateVo> list = indexStatisticsService.findGradeCompletionVoList(areaTeamId,Utils.toLongIds(busTeamIds),Utils.toLongIds(periodIds),Utils.toLongIds(gradeIds),null);
        return ReturnResult.success(list);
    }


    @ApiOperation("导出校区续读统计（营运指标）")
    @RequestMapping(value = "/exportGradeCompletionRate",method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Page<GradeCompletionRateVo>> exportGradeCompletionRate(@RequestParam("areaTeamId") long areaTeamId,@RequestParam(value = "periodIds") String periodIds, @RequestParam("busTeamIds")String busTeamIds, @RequestParam("gradeIds")String gradeIds, HttpServletRequest request, HttpServletResponse response) throws IOException {

        Webs.writeExcel(request, response, indexStatisticsService.exportGradeCompletionRate(areaTeamId,Utils.toLongIds(busTeamIds),Utils.toLongIds(periodIds),Utils.toLongIds(gradeIds)), "校区续读统计（营运指标）");
        return ReturnResult.success("ok");
    }


    @ApiOperation("班主任续读统计（营运指标）")
    @RequestMapping(value = "/findSeniorComletionRateVoPage", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Page<SeniorCompletionRateVo>> findSeniorComletionRateVoPage(@ModelAttribute TeacherQueryVo teacherQueryVo,@ModelAttribute RegRelativceQueryVo regRelativceQueryVo,@RequestParam(value = "teacherType",defaultValue = "seniorId")String teacherType,@RequestParam(value = "periodIds") String periodIds,@RequestParam(value = "gradeIds",required = false)String gradeIds, @RequestParam("busTeamIds")String busTeamIds, @RequestParam("pageNo")int pageNo,@RequestParam("pageSize")int pageSize,HttpServletRequest request) {
        teacherQueryVo.setAccessType(1);
        Page<SeniorCompletionRateVo> list = indexStatisticsService.findSeniorComletionRateVoPage(teacherQueryVo,Utils.toLongIds(busTeamIds),Utils.toLongIds(periodIds),Utils.toLongIds(gradeIds),pageNo,pageSize);
        //Page<SeniorCompletionRateVo> list = indexStatisticsService.findSeniorComletionRateVoPage(teacherQueryVo,regRelativceQueryVo,teacherType,Arrays.asList(4,5),Utils.toLongIds(busTeamIds),Utils.toLongIds(periodIds),pageNo,pageSize);
        return ReturnResult.success(list);
    }

    @ApiOperation("导出班主任续读统计（营运指标）")
    @RequestMapping(value = "/exportSeniorComletionRate",method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Page<SeniorCompletionRateVo>> exportSeniorComletionRate(@ModelAttribute TeacherQueryVo teacherQueryVo,@ModelAttribute RegRelativceQueryVo regRelativceQueryVo,@RequestParam(value = "gradeIds",required = false) String gradeIds,@RequestParam(value = "teacherType",defaultValue = "seniorId")String teacherType,@RequestParam(value = "periodIds") String periodIds, @RequestParam("busTeamIds")String busTeamIds,  HttpServletRequest request, HttpServletResponse response) throws IOException {
        teacherQueryVo.setAccessType(1);
        Webs.writeExcel(request, response, indexStatisticsService.exportSeniorComletionRate(teacherQueryVo,Utils.toLongIds(busTeamIds),Utils.toLongIds(periodIds),Utils.toLongIds(gradeIds)), "班主任续读统计（营运指标）");
        return ReturnResult.success("ok");
    }


    @ApiOperation("咨询师科数统计（营运指标）")
    @RequestMapping(value = "/findCounselorComletionRateVoPage", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Page<CounselorRateVo>> findCounselorComletionRateVoPage(@ModelAttribute TeacherQueryVo teacherQueryVo,  @RequestParam(value = "periodIds") String periodIds, @RequestParam("busTeamIds")String busTeamIds,
                                                                                       @RequestParam(value = "startRecordRegTime" ,required = false) Date startRecordRegTime,
                                                                                       @RequestParam(value = "endRecordRegTime",required = false) Date endRecordRegTime,
                                                                                       @RequestParam("pageNo")int pageNo, @RequestParam("pageSize")int pageSize, HttpServletRequest request) {
        teacherQueryVo.setAccessType(1);
        PeriodQueryRegVo periodQueryRegVo=new PeriodQueryRegVo();
        periodQueryRegVo.setChargingStatus(2);
       // periodQueryRegVo.setLectureNum(5);
        periodQueryRegVo.setRegStatus(0);
        periodQueryRegVo.setStartDate(startRecordRegTime);
        if (endRecordRegTime!=null){
            periodQueryRegVo.setEndDate(endRecordRegTime);
        }
        Page<CounselorRateVo> list = indexStatisticsService.findCounselorComletionRateVoPage(periodQueryRegVo,teacherQueryVo,Utils.toLongIds(busTeamIds),Utils.toLongIds(periodIds),pageNo,pageSize);
        return ReturnResult.success(list);
    }

    @ApiOperation("咨询师科数统计（营运指标）")
    @RequestMapping(value = "/exportCounselorComletionRateVoPage", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Void> exportCounselorComletionRateVoPage(@ModelAttribute TeacherQueryVo teacherQueryVo,
                                                                 @RequestParam(value = "startRecordRegTime" ,required = false) Date startRecordRegTime,
                                                                 @RequestParam(value = "endRecordRegTime",required = false) Date endRecordRegTime,
                                                                  @RequestParam(value = "periodIds") String periodIds, @RequestParam("busTeamIds")String busTeamIds, HttpServletRequest request,HttpServletResponse response)  throws IOException{
        teacherQueryVo.setAccessType(1);
        PeriodQueryRegVo periodQueryRegVo=new PeriodQueryRegVo();
        periodQueryRegVo.setChargingStatus(2);
       // periodQueryRegVo.setLectureNum(5);
        periodQueryRegVo.setRegStatus(0);
        periodQueryRegVo.setStartDate(startRecordRegTime);
        if (endRecordRegTime!=null){
            periodQueryRegVo.setEndDate(endRecordRegTime);
        }
        Webs.writeExcel(request, response, indexStatisticsService.exportCounselorComletionRateVoPage(periodQueryRegVo,teacherQueryVo,Utils.toLongIds(busTeamIds),Utils.toLongIds(periodIds)), "咨询师科数（营运指标）");
        return ReturnResult.success("ok");
    }


    @ApiOperation("营业概况")
    @RequestMapping(value = "/findBusinessSituationList", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Page<BusinessSituationVo>> findBusinessSituationList(@RequestParam("areaTeamId")Long areaTeamId,@RequestParam(value = "periodIds") String periodIds, @RequestParam("busTeamIds")String busTeamIds,@RequestParam("gradeIds")String gradeIds,@RequestParam(value = "subjectIds",required = false)String subjectIds,@RequestParam(value = "startDate",required = false)Date startDate,@RequestParam("endDate")Date endDate,@RequestParam("needWithPeriod")int needWithPeriod,HttpServletRequest request) {
        DataPermission dataPermission=this.getDataPermission(request);
        List<BusinessSituationVo> businessSituationVoList=indexStatisticsService.findBusinessSituationList(dataPermission,areaTeamId,Utils.toLongIds(busTeamIds),Utils.toLongIds(periodIds),Utils.toLongIds(gradeIds),Utils.toLongIds(subjectIds),startDate,endDate,needWithPeriod,0).getBusinessSituationVoList();
        return ReturnResult.success(businessSituationVoList);
    }

    @ApiOperation("导出营业概况")
    @RequestMapping(value = "/exportBusinessSituation",method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Page<SeniorCompletionRateVo>> exportBusinessSituation(@RequestParam("areaTeamId")Long areaTeamId,@RequestParam(value = "periodIds") String periodIds, @RequestParam("busTeamIds")String busTeamIds,@RequestParam("gradeIds")String gradeIds,@RequestParam(value = "subjectIds",required = false)String subjectIds,@RequestParam(value = "startDate",required = false)Date startDate,@RequestParam("endDate")Date endDate,@RequestParam("needWithPeriod")int needWithPeriod, HttpServletRequest request, HttpServletResponse response) throws IOException {
        DataPermission dataPermission=this.getDataPermission(request);
        Webs.writeExcel(request, response, indexStatisticsService.exportBusinessSituation(dataPermission,areaTeamId,Utils.toLongIds(busTeamIds),Utils.toLongIds(periodIds),Utils.toLongIds(gradeIds),Utils.toLongIds(subjectIds),startDate,endDate,needWithPeriod), "营业概况");
        return ReturnResult.success("ok");
    }


    @ApiOperation("看板")
    @RequestMapping(value = "/findBlockVo", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<BlockVo> findBlockVo(@RequestParam("areaTeamId")Long areaTeamId,@RequestParam(value = "periodIds") String periodIds, @RequestParam(value = "busTeamIds",required = false)String busTeamIds,@RequestParam("gradeIds")String gradeIds,@RequestParam(value = "subjectIds",required = false)String subjectIds,@RequestParam(value = "startDate",required = false)Date startDate,@RequestParam(value = "endDate",required = false)Date endDate,HttpServletRequest request) {
        if (endDate==null){
            endDate=TimeUtils.changeOneDateLastTime(new Date());
        }
        DataPermission dataPermission=this.getDataPermission(request);

        BlockVo blockVo=indexStatisticsService.findBlockVo(dataPermission,areaTeamId,Utils.toLongIds(busTeamIds),Utils.toLongIds(periodIds),Utils.toLongIds(gradeIds),Utils.toLongIds(subjectIds),startDate,endDate);
        return ReturnResult.success(blockVo);
    }

    @ApiOperation("导出看板")
    @RequestMapping(value = "/exportBlock",method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<BlockVo> exportBlock(@RequestParam("areaTeamId")Long areaTeamId,@RequestParam(value = "periodIds") String periodIds, @RequestParam("busTeamIds")String busTeamIds,@RequestParam("gradeIds")String gradeIds,@RequestParam(value = "subjectIds",required = false)String subjectIds,@RequestParam(value = "startDate",required = false)Date startDate,@RequestParam(value = "endDate",required = false)Date endDate,HttpServletRequest request, HttpServletResponse response) throws IOException {
        if (endDate==null){
            endDate=TimeUtils.changeOneDateLastTime(new Date());
        }
        DataPermission dataPermission=this.getDataPermission(request);

        Webs.writeExcel(request, response, indexStatisticsService.exportBlock(dataPermission,areaTeamId,Utils.toLongIds(busTeamIds),Utils.toLongIds(periodIds),Utils.toLongIds(gradeIds),Utils.toLongIds(subjectIds),startDate,endDate), "看板");
        return ReturnResult.success("ok");
    }


    @ApiOperation("每日营业概况")
    @RequestMapping(value = "/findAmountBranchPerson", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<AmountBranchPerson> findAmountBranchPerson(@RequestParam("areaTeamId")Long areaTeamId,@RequestParam(value = "periodIds") String periodIds, @RequestParam(value = "busTeamIds",required = false)String busTeamIds,@RequestParam("gradeIds")String gradeIds,@RequestParam(value = "startDate")Date startDate,@RequestParam(value = "endDate")Date endDate,HttpServletRequest request) {
        if (endDate!=null){
            endDate=TimeUtils.changeOneDateLastTime(endDate);
            //regRelativceQueryVo.setEndRecordRegTime(TimeUtils.changeOneDateLastTime(regRelativceQueryVo.getEndRecordRegTime()));
        }
        List<Long> busTeamIdList=Utils.toLongIds(busTeamIds);
        if (busTeamIdList==null || busTeamIdList.size()<=0){
            busTeamIdList=dataStatisticsService.findPermissionBusTeam(Arrays.asList(areaTeamId),this.getUserId(request));
        }
        AmountBranchPerson amountBranchPerson=indexStatisticsService.findAmountBranchPerson(busTeamIdList,areaTeamId,Utils.toLongIds(periodIds),Utils.toLongIds(gradeIds),startDate,endDate);
        return ReturnResult.success(amountBranchPerson);
    }

    @ApiOperation("导出每日营业概况")
    @RequestMapping(value = "/exportAmountBranchPerson",method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<AmountBranchPerson> exportAmountBranchPerson(@RequestParam("areaTeamId")Long areaTeamId,@RequestParam(value = "periodIds") String periodIds, @RequestParam(value = "busTeamIds",required = false)String busTeamIds,@RequestParam("gradeIds")String gradeIds,@RequestParam(value = "startDate")Date startDate,@RequestParam(value = "endDate")Date endDate,HttpServletRequest request, HttpServletResponse response) throws IOException {
        if (endDate!=null){
            endDate=TimeUtils.changeOneDateLastTime(endDate);
            //regRelativceQueryVo.setEndRecordRegTime(TimeUtils.changeOneDateLastTime(regRelativceQueryVo.getEndRecordRegTime()));
        }
        List<Long> busTeamIdList=Utils.toLongIds(busTeamIds);
        if (busTeamIdList==null || busTeamIdList.size()<=0){
            busTeamIdList=dataStatisticsService.findPermissionBusTeam(Arrays.asList(areaTeamId),this.getUserId(request));
        }
        Webs.writeExcel(request, response, indexStatisticsService.exportAmountBranchPerson(busTeamIdList,areaTeamId,Utils.toLongIds(periodIds),Utils.toLongIds(gradeIds),startDate,endDate), "每日营业概况");
        return ReturnResult.success("ok");
    }


    @ApiOperation("招生提成")
    @RequestMapping(value = "/findTeacherCommission",method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Page<TeacherCommissionDetail>> findTeacherCommission(@ModelAttribute TeacherQueryVo teacherQueryVo,@RequestParam("periodTypeQueryVoJson")String periodTypeQueryVoJson,@RequestParam(value = "pageNo")int pageNo,@RequestParam(value = "pageSize")int pageSize, HttpServletRequest request, HttpServletResponse response)  {
        DataPermission dataPermission=this.getDataPermission(request);
        teacherQueryVo.setAccessType(1);
        List<PeriodTypeQueryVo> periodTypeQueryVoList=JSONObject.parseArray(periodTypeQueryVoJson,PeriodTypeQueryVo.class);
        Page<TeacherCommissionDetail> page=indexStatisticsService.findTeacherCommissionPage(teacherQueryVo,dataPermission,periodTypeQueryVoList,pageNo,pageSize);
        return ReturnResult.success(page);
    }

    @ApiOperation("导出招生提成")
    @RequestMapping(value = "/exportTeacherCommission",method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Void> exportTeacherCommission(@ModelAttribute TeacherQueryVo teacherQueryVo,@RequestParam("periodTypeQueryVoJson")String periodTypeQueryVoJson, HttpServletRequest request, HttpServletResponse response)  throws IOException {
        DataPermission dataPermission=this.getDataPermission(request);
        teacherQueryVo.setAccessType(1);
        List<PeriodTypeQueryVo> periodTypeQueryVoList=JSONObject.parseArray(periodTypeQueryVoJson,PeriodTypeQueryVo.class);
        Webs.writeExcel(request, response, indexStatisticsService.exportTeacherCommission(teacherQueryVo,dataPermission,periodTypeQueryVoList), "招生提成参数");
        return ReturnResult.success("ok");
    }


    @ApiOperation("同步tms报读数据")
    @RequestMapping(value = "/findZyExternalReg", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<List<ExternalCampusRegVo>> findZyExternalReg(@RequestParam(value = "gradeId",defaultValue = "23")Long gradeId,@RequestParam("periodIds")String periodIds, HttpServletRequest request) {
        List<Period> periodList=periodService.findByIds(Utils.toLongIds(periodIds));
        Period period=periodList.get(0);
        AreaTeam areaTeam=areaTeamService.findById(period.getAreaTeamId());
        BaseGrade baseGrade=baseGradeService.findById(gradeId);
        String seasonName=this.getSeasonByPeriodName(period.getPeriodName());
        String yearName=this.getYearNameByPeriodName(period.getPeriodName());
        externalRegDetailService.findExternalReg(areaTeam,Arrays.asList(period),Arrays.asList(baseGrade),yearName,Arrays.asList(seasonName),Arrays.asList(baseGrade.getGradeName()));
        return ReturnResult.success("ok");
    }

    private String getYearNameByPeriodName(String periodName){
        String yearName=periodName.substring(0,4);
        return yearName;
    }
    private String getSeasonByPeriodName(String periodName){
        if (periodName.contains("春")){
            return "春季班";
        }else if (periodName.contains("秋")){
            return "秋季班";
        }else if (periodName.contains("暑")){
            return "暑假班";
        }else if (periodName.contains("寒")){
            return "寒假班";
        }
        return null;
    }


    @ApiOperation("校区续读（初三）")
    @RequestMapping(value = "/findExternalCampusReg", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<List<ExternalCampusRegVo>> findExternalCampusReg(@ModelAttribute ExternalRegQueryVo externalRegQueryVo,  @RequestParam(value = "periodIds")String periodIds, HttpServletRequest request) {
        externalRegQueryVo.setGradeId(23L);
        externalRegQueryVo.setRegStatus(0);
        externalRegQueryVo.setChargingStatus(2);
        externalRegQueryVo.setBigLectureNum(5);
        externalRegQueryVo.setGradeId(23L);
        List<ExternalCampusRegVo> externalCampusRegVoList=indexStatisticsService.findExternalCampusReg(Utils.toLongIds(periodIds), externalRegQueryVo);
        return ReturnResult.success(externalCampusRegVoList);
    }

    @ApiOperation("导出校区续读（初三）")
    @RequestMapping(value = "/exportExternalCampusReg", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Void> exportExternalCampusReg(@ModelAttribute ExternalRegQueryVo externalRegQueryVo, @RequestParam(value = "bigLectureNum",required = false,defaultValue = "5")Integer bigLectureNum, @RequestParam(value = "periodIds")String periodIds, HttpServletRequest request, HttpServletResponse response) throws IOException {
        externalRegQueryVo.setGradeId(23L);
        externalRegQueryVo.setRegStatus(0);
        externalRegQueryVo.setChargingStatus(2);
        externalRegQueryVo.setBigLectureNum(5);
        externalRegQueryVo.setGradeId(23L);
        Webs.writeExcel(request, response, indexStatisticsService.exportExternalCampusReg(Utils.toLongIds(periodIds), externalRegQueryVo), "校区续读（初三）");
        return ReturnResult.success("ok");
    }

    @ApiOperation("班主任续读（初三）")
    @RequestMapping(value = "/findExternalSeniorReg", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<List<ExternalCampusRegVo>> findExternalSeniorReg(@ModelAttribute ExternalRegQueryVo externalRegQueryVo, @RequestParam(value = "bigLectureNum",required = false,defaultValue = "5")Integer bigLectureNum, @RequestParam(value = "periodIds")String periodIds, HttpServletRequest request) {
        externalRegQueryVo.setGradeId(23L);
        externalRegQueryVo.setRegStatus(0);
        externalRegQueryVo.setChargingStatus(2);
        externalRegQueryVo.setBigLectureNum(5);
        List<ExternalSeniorRegVo> externalSeniorRegVoList=indexStatisticsService.findExternalSeniorReg(Utils.toLongIds(periodIds), externalRegQueryVo);
        return ReturnResult.success(externalSeniorRegVoList);
    }

    @ApiOperation("导出班主任续读（初三）")
    @RequestMapping(value = "/exportExternalSeniorReg", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Void> exportExternalSeniorReg(@ModelAttribute ExternalRegQueryVo externalRegQueryVo,  @RequestParam(value = "periodIds")String periodIds, HttpServletRequest request,HttpServletResponse response) throws IOException {
        externalRegQueryVo.setGradeId(23L);
        externalRegQueryVo.setRegStatus(0);
        externalRegQueryVo.setChargingStatus(2);
        externalRegQueryVo.setBigLectureNum(5);
        externalRegQueryVo.setGradeId(23L);
        Webs.writeExcel(request, response, indexStatisticsService.exportExternalSeniorReg(Utils.toLongIds(periodIds), externalRegQueryVo), "班主任续读（初三）");
        return ReturnResult.success("ok");
    }

    @ApiOperation("初三班主任推广数据")
    @RequestMapping(value = "/findAcademicAdvisorData", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<List<ExternalCampusRegVo>> findAcademicAdvisorData(@RequestParam("areaTeamId")long areaTeamId,@ModelAttribute TeacherQueryVo teacherQueryVo,@RequestParam("startDate")Date startDate,@RequestParam("endDate")Date endDate,@RequestParam("pageNo")int pageNo,@RequestParam("pageSize")int pageSize, HttpServletRequest request) {
        teacherQueryVo.setAccessType(2);//外部班主任
        endDate=TimeUtils.changeOneDateLastTime(endDate);
        Page<AcademicAdvisorDataVo> academicAdvisorDataPage = indexStatisticsService.findAcademicAdvisorData(areaTeamId, teacherQueryVo, startDate, endDate, pageNo, pageSize);
        return ReturnResult.success(academicAdvisorDataPage);
    }

    @ApiOperation("导出初三班主任推广数据")
    @RequestMapping(value = "/exportAcademicAdvisorData", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<List<ExternalCampusRegVo>> exportAcademicAdvisorData(@RequestParam("areaTeamId")long areaTeamId,@ModelAttribute TeacherQueryVo teacherQueryVo,@RequestParam("startDate")Date startDate,@RequestParam("endDate")Date endDate, HttpServletRequest request,HttpServletResponse response) throws IOException  {
        teacherQueryVo.setAccessType(2);//外部班主任
        endDate=TimeUtils.changeOneDateLastTime(endDate);
        Webs.writeExcel(request, response, indexStatisticsService.exportAcademicAdvisorData(areaTeamId, teacherQueryVo, startDate, endDate), "初三班主任推广数据");
        return ReturnResult.success("ok");
    }


    @ApiOperation("班别明细")
    @RequestMapping(value = "/findClassRegDetailPage", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Page<ClassRegDetailVo>> findClassRegDetailPage(@RequestParam(value = "className",required = false)String className,
                                                                        @RequestParam(value = "classNo",required = false) String classNo,
                                                                       @RequestParam(value = "teacherName",required = false)String teacherName,@RequestParam(value = "areaTeamId")long areaTeamId,@RequestParam(value = "periodIds",required = true)String periodIds,@RequestParam(value = "busTeamIds",required = false)String busTeamIds,@RequestParam(value = "gradeIds",required = false)String gradeIds,@RequestParam(value = "subjectId",required = false)Long subjectId, @RequestParam("pageNo") int pageNo,@RequestParam("pageSize") int pageSize,HttpServletRequest request) {
        if (StringUtils.isEmpty(periodIds)){
            throw new BusException("期数必选");
        }
        DataPermission dataPermission=this.getDataPermission(request);
        CourseClassQueryVo courseClassQueryVo=new CourseClassQueryVo();
        courseClassQueryVo.setPeriodIds(Utils.toLongIds(periodIds));
        if (StringUtils.isNotEmpty(className)){
            courseClassQueryVo.setClassName(className);
        }
        if (StringUtils.isNotEmpty(teacherName)){
            courseClassQueryVo.setTeacherName(teacherName);
        }
        if (StringUtils.isNotEmpty(busTeamIds)){
            courseClassQueryVo.setBusTeamIds(Utils.toLongIds(busTeamIds));
        }
        if (StringUtils.isNotEmpty(gradeIds)){
            courseClassQueryVo.setGradeIds(Utils.toLongIds(gradeIds));
        }
        if (subjectId!=null){
            courseClassQueryVo.setSubjectIds(Arrays.asList(subjectId));
        }
        courseClassQueryVo.setClassNo(classNo);
        courseClassQueryVo.setStatusList(Arrays.asList(1,3));
        Page<ClassRegDetailVo> classRegDetailPage = indexStatisticsService.findClassRegDetailPage(courseClassQueryVo,dataPermission, pageNo, pageSize);
        return ReturnResult.success(classRegDetailPage);
    }

    @ApiOperation("导出班别明细")
    @RequestMapping(value = "/exportClassRegDetail", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Void> exportClassRegDetail( @RequestParam(value = "subjectId",required = false)Long subjectId,@RequestParam(value = "classNo",required = false) String classNo,@RequestParam(value = "className",required = false)String className,@RequestParam(value = "teacherName",required = false)String teacherName,@RequestParam(value = "areaTeamId")long areaTeamId,@RequestParam(value = "periodIds",required = true)String periodIds,@RequestParam(value = "busTeamIds",required = false)String busTeamIds,@RequestParam(value = "gradeIds",required = false)String gradeIds,@RequestParam(value = "subjectIds",required = false)String subjectIds, HttpServletRequest request,HttpServletResponse response) throws IOException {
        if (StringUtils.isEmpty(periodIds)){
            throw new BusException("期数必选");
        }
        DataPermission dataPermission=this.getDataPermission(request);
        CourseClassQueryVo courseClassQueryVo=new CourseClassQueryVo();
        courseClassQueryVo.setPeriodIds(Utils.toLongIds(periodIds));
        if (StringUtils.isNotEmpty(className)){
            courseClassQueryVo.setClassName(className);
        }
        if (StringUtils.isNotEmpty(teacherName)){
            courseClassQueryVo.setTeacherName(teacherName);
        }
        if (StringUtils.isNotEmpty(busTeamIds)){
            courseClassQueryVo.setBusTeamIds(Utils.toLongIds(busTeamIds));
        }
        if (StringUtils.isNotEmpty(gradeIds)){
            courseClassQueryVo.setGradeIds(Utils.toLongIds(gradeIds));
        }
        if (subjectId!=null){
            courseClassQueryVo.setSubjectIds(Arrays.asList(subjectId));
        }
        courseClassQueryVo.setClassNo(classNo);
        courseClassQueryVo.setStatusList(Arrays.asList(1,3));

        Webs.writeExcel(request, response, indexStatisticsService.exportClassRegDetail(courseClassQueryVo,dataPermission), "班级明细");
        return ReturnResult.success("ok");
    }

    @ApiOperation("网报排行榜")
    @RequestMapping(value = "/findOnlineList", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<OnlineList> findOnlineList(@RequestParam("areaTeamId")long areaTeamId,@RequestParam("periodIds")String periodIds,@ModelAttribute PeriodQueryRegVo periodQueryRegVo,HttpServletRequest request) {
        periodQueryRegVo.setRegStatus(0);
        periodQueryRegVo.setChargingStatus(2);
        OnlineList onlineList=indexStatisticsService.findOnlineList(areaTeamId,Utils.toLongIds(periodIds),periodQueryRegVo);
        return ReturnResult.success(onlineList);
    }

    @ApiOperation("导出初三班主任推广数据")
    @RequestMapping(value = "/exportOnlineList", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Void> exportOnlineList(@RequestParam("areaTeamId")long areaTeamId,@RequestParam("periodIds")String periodIds,@ModelAttribute PeriodQueryRegVo periodQueryRegVo, HttpServletRequest request,HttpServletResponse response) throws IOException  {
        periodQueryRegVo.setRegStatus(0);
        periodQueryRegVo.setChargingStatus(2);
        Webs.writeExcel(request, response, indexStatisticsService.exportOnlineList(areaTeamId, Utils.toLongIds(periodIds), periodQueryRegVo), "网报排行榜");
        return ReturnResult.success("ok");
    }


    @ApiOperation("待处理事项")
    @RequestMapping(value = "/findNeedToDeal", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<List<NeedDealNumVo>> findNeedToDeal(@RequestParam("areaTeamId")long areaTeamId,HttpServletRequest request) {
        DataPermission dataPermission=this.getDataPermission(request);
        List<NeedDealNumVo> needDealNumVoList=indexStatisticsService.countResourceNeedToDeal(areaTeamId,dataPermission);
        return ReturnResult.success(needDealNumVoList);
    }

    @ApiOperation("数据看板，不包括校区续读")
    @RequestMapping(value = "/findDataCount", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<DataCountVo> findDataCount(@RequestParam("year") String year,@ApiParam("区域id")@RequestParam("areaTeamId")long areaTeamId, @ApiParam("期数id，以逗号隔开")@RequestParam("periodIds")String periodIds, @ApiParam("年级id，以逗号隔开") @RequestParam(value = "gradeIds",required = false)String gradeIds, HttpServletRequest request) {
        DataPermission dataPermission=this.getDataPermission(request);
        DataCountVo dataCountVo=indexStatisticsService.findDataCount(year,dataPermission,areaTeamId,Utils.toLongIds(periodIds),Utils.toLongIds(gradeIds));
        return ReturnResult.success(dataCountVo);
    }

    @ApiOperation("数据看板，校区续读")
    @RequestMapping(value = "/findCampusSeqStepRate", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<CampusSeqStepRateVo> findCampusSeqStepRate(@RequestParam("year") String year,@RequestParam("areaTeamId")long areaTeamId,@RequestParam("periodIds")String periodIds,@RequestParam(value = "gradeIds",required = false)String gradeIds, HttpServletRequest request) {
        DataPermission dataPermission=this.getDataPermission(request);
        CampusSeqStepRateVo campusSeqStepRateVo=indexStatisticsService.findCampusSeqStepRate(year,areaTeamId,dataPermission,Utils.toLongIds(periodIds),Utils.toLongIds(gradeIds));
        return ReturnResult.success(campusSeqStepRateVo);
    }

   /* @ApiOperation("退费概况")
    @RequestMapping(value = "/findCampusSeqStepRate", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<CampusSeqStepRateVo> findCampusSeqStepRate(@RequestParam("year") String year,@RequestParam("areaTeamId")long areaTeamId,@RequestParam("periodIds")String periodIds,@RequestParam(value = "gradeIds",required = false)String gradeIds, HttpServletRequest request) {
        DataPermission dataPermission=this.getDataPermission(request);
        CampusSeqStepRateVo campusSeqStepRateVo=indexStatisticsService.findCampusSeqStepRate(year,areaTeamId,dataPermission,Utils.toLongIds(periodIds),Utils.toLongIds(gradeIds));
        return ReturnResult.success(campusSeqStepRateVo);
    }*/

    @ApiOperation(value = "短信验证码列表" )
    @RequestMapping(value = { "/smsPage" } ,method = { RequestMethod.GET ,RequestMethod.POST })
    @ResponseBody
    public ReturnResult<Page<Sms>> sendCode(@ModelAttribute SmsQueryVo smsQueryVo,@RequestParam("pageNo") int pageNo,@RequestParam("pageSize") int pageSize) {
        Page<Sms> smsCodePage = smsService.findSmsCodePage(smsQueryVo,pageNo,pageSize);
        return ReturnResult.success(smsCodePage);

    }


    @ApiOperation("退费概况")
    @RequestMapping(value = "/refundSituationPage", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Page<RefundSituationVo>> refundSituationPage(@RequestParam(value = "areaTeamId") long areaTeamId,@RequestParam(name = "busTeamId",required = false)Long busTeamId,
                                                                        @RequestParam(value = "periodId",required = false)Long periodId,
                                                                        @RequestParam(value = "gradeId",required = false)Long gradeId,
                                                                        @RequestParam(value = "subjectIds",required = false)String subjectIds,
                                                                        @RequestParam(value = "refundWay",required = false)Integer refundWay,
                                                                        @RequestParam(value = "pageNo")int pageNo,@RequestParam(value = "pageSize") int pageSize,
        HttpServletRequest request) {
        DataPermission dataPermission=this.getDataPermission(request);
        StudentRegDetailQueryVo studentRegDetailQueryVo=new StudentRegDetailQueryVo();
        studentRegDetailQueryVo.setBusTeamId(busTeamId);
        studentRegDetailQueryVo.setAreaTeamId(areaTeamId);
        studentRegDetailQueryVo.setPeriodId(periodId);
        studentRegDetailQueryVo.setGradeId(gradeId);
        studentRegDetailQueryVo.setSubjectIds(Utils.toLongIds(subjectIds));
        studentRegDetailQueryVo.setRegStatusList(Arrays.asList(0,3));
        Page<RefundSituationVo> page=refundStatisticsService.findRefundSituation(dataPermission,studentRegDetailQueryVo,refundWay,pageNo,pageSize);
        return ReturnResult.success(page);
    }

    @ApiOperation("退费概况总数")
    @RequestMapping(value = "/sumRefundSituation", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<SumRefundSituation> sumRefundSituation(@RequestParam(value = "areaTeamId") long areaTeamId,@RequestParam(name = "busTeamId",required = false)Long busTeamId,
                                                                     @RequestParam(value = "periodId",required = false)Long periodId,
                                                                     @RequestParam(value = "gradeId",required = false)Long gradeId,
                                                                     @RequestParam(value = "subjectIds",required = false)String subjectIds,
                                                                     @RequestParam(value = "refundWay",required = false)Integer refundWay,
                                                                     HttpServletRequest request) {
        DataPermission dataPermission=this.getDataPermission(request);
        StudentRegDetailQueryVo studentRegDetailQueryVo=new StudentRegDetailQueryVo();
        studentRegDetailQueryVo.setBusTeamId(busTeamId);
        studentRegDetailQueryVo.setAreaTeamId(areaTeamId);
        studentRegDetailQueryVo.setPeriodId(periodId);
        studentRegDetailQueryVo.setGradeId(gradeId);
        studentRegDetailQueryVo.setSubjectIds(Utils.toLongIds(subjectIds));
        studentRegDetailQueryVo.setRegStatusList(Arrays.asList(0,3));
        SumRefundSituation sumRefundSituation=refundStatisticsService.findSumRefundSituation(dataPermission,studentRegDetailQueryVo,refundWay);
        return ReturnResult.success(sumRefundSituation);
    }




    @ApiOperation("导出退费概况")
    @RequestMapping(value = "/exportRefundSituation", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Void> exportRefundSituation(@RequestParam(value = "areaTeamId") long areaTeamId,@RequestParam(name = "busTeamId",required = false)Long busTeamId,
                                                    @RequestParam(value = "periodId",required = false)Long periodId,
                                                    @RequestParam(value = "gradeId",required = false)Long gradeId,
                                                    @RequestParam(value = "subjectIds",required = false)String subjectIds,
                                                    @RequestParam(value = "refundWay",required = false)Integer refundWay,
                                                    HttpServletRequest request,HttpServletResponse response) throws IOException {
        DataPermission dataPermission=this.getDataPermission(request);
        StudentRegDetailQueryVo studentRegDetailQueryVo=new StudentRegDetailQueryVo();
        studentRegDetailQueryVo.setAreaTeamId(areaTeamId);
        studentRegDetailQueryVo.setBusTeamId(busTeamId);
        studentRegDetailQueryVo.setPeriodId(periodId);
        studentRegDetailQueryVo.setGradeId(gradeId);
        studentRegDetailQueryVo.setSubjectIds(Utils.toLongIds(subjectIds));
        studentRegDetailQueryVo.setRegStatusList(Arrays.asList(0,3));
        Webs.writeExcel(request, response, refundStatisticsService.exportRefundSituation(dataPermission,studentRegDetailQueryVo,refundWay), "退费概况");
        return ReturnResult.success("ok");
    }

    @ApiOperation("退费详情")
    @RequestMapping(value = "/findRefundDetail", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Page<RefundDetailVo>> findRefundDetail(@RequestParam(value = "areaTeamId") long areaTeamId,@RequestParam(name = "busTeamId",required = false)Long busTeamId,
                                                                       @RequestParam(value = "periodId",required = false)Long periodId,
                                                                       @RequestParam(value = "gradeId",required = false)Long gradeId,
                                                                       @RequestParam(value = "subjectIds",required = false)String subjectIds,
                                                                       @RequestParam(value = "refundWay",required = false)Integer refundWay,
                                                                       @RequestParam(value = "pageNo")int pageNo,@RequestParam(value = "pageSize") int pageSize,
                                                                       HttpServletRequest request) {
        DataPermission dataPermission=this.getDataPermission(request);
        StudentRefundQueryVo studentRefundQueryVo=new StudentRefundQueryVo();
        studentRefundQueryVo.setBusTeamId(busTeamId);
        studentRefundQueryVo.setAreaTeamId(areaTeamId);
        studentRefundQueryVo.setPeriodId(periodId);
        studentRefundQueryVo.setGradeId(gradeId);
        studentRefundQueryVo.setSubjectIds(Utils.toLongIds(subjectIds));
        Page<RefundDetailVo> page=refundStatisticsService.findRefundDetail(dataPermission,studentRefundQueryVo,pageNo,pageSize);
        return ReturnResult.success(page);
    }

    @ApiOperation("导出退费详情")
    @RequestMapping(value = "/exportRefundDetail", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Void> exportRefundDetail(@RequestParam(value = "areaTeamId") long areaTeamId,@RequestParam(name = "busTeamId",required = false)Long busTeamId,
                                                    @RequestParam(value = "periodId",required = false)Long periodId,
                                                    @RequestParam(value = "gradeId",required = false)Long gradeId,
                                                    @RequestParam(value = "subjectIds",required = false)String subjectIds,
                                                    @RequestParam(value = "refundWay",required = false)Integer refundWay,
                                                    HttpServletRequest request,HttpServletResponse response) throws IOException {
        DataPermission dataPermission=this.getDataPermission(request);
        StudentRefundQueryVo studentRefundQueryVo=new StudentRefundQueryVo();
        studentRefundQueryVo.setBusTeamId(busTeamId);
        studentRefundQueryVo.setAreaTeamId(areaTeamId);
        studentRefundQueryVo.setPeriodId(periodId);
        studentRefundQueryVo.setGradeId(gradeId);
        studentRefundQueryVo.setSubjectIds(Utils.toLongIds(subjectIds));
        Webs.writeExcel(request, response, refundStatisticsService.exportRefundDetail(dataPermission,studentRefundQueryVo), "退费详情");
        return ReturnResult.success("ok");
    }


    @ApiOperation("优惠卷使用概况")
    @RequestMapping(value = "/findDiscountCodeUseDetail", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Page<DiscountCodeUseDetailVo>> findDiscountCodeUseDetail(@ModelAttribute CourseOrderDiscountQueryVo courseOrderDiscountQueryVo,@RequestParam("pageNo")int pageNo,@RequestParam("pageSize") int pageSize, HttpServletRequest request) {
        Page<DiscountCodeUseDetailVo> discountCodeUseDetailVoPage = courseOrderDiscountService.findDiscountCodeUseDetail(courseOrderDiscountQueryVo, pageNo, pageSize);
        return ReturnResult.success(discountCodeUseDetailVoPage);
    }

    @ApiOperation("导出优惠卷使用概况")
    @RequestMapping(value = "/exportDiscountCodeUseDetail", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Page<DiscountCodeUseDetailVo>> exportDiscountCodeUseDetail(@ModelAttribute CourseOrderDiscountQueryVo courseOrderDiscountQueryVo, HttpServletRequest request,HttpServletResponse response) throws IOException  {
        Webs.writeExcel(request, response, courseOrderDiscountService.exportDiscountCodeUseDetail(courseOrderDiscountQueryVo), "优惠卷使用概况");
        return ReturnResult.success("ok");
    }

    @ApiOperation("满班率剔除特殊班级设置")
    @RequestMapping(value = "/fullClassForbidSetting", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Void> fullClassForbidSetting(@ModelAttribute ClassForbiddenPropertiesVo classForbiddenPropertiesVo,@RequestParam("areaTeamId") Long areaTeamId){
        dataStatisticsService.fullClassForbidSetting(classForbiddenPropertiesVo,areaTeamId);
        return ReturnResult.success("ok");
    }

    @ApiOperation("查询满班率剔除特殊班级设置")
    @RequestMapping(value = "/queryfullClassForbidSetting", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Map<String,String>> queryfullClassForbidSetting(@RequestParam("areaTeamId") Long areaTeamId){
        return ReturnResult.success(dataStatisticsService.getFullClassForbidSettingMap(areaTeamId));
    }

    @ApiOperation("统计设置")
    @RequestMapping(value = "/saveReportConfigs", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Map<String,String>> saveReportConfigs(@RequestBody ReportConfigSaveOrUpdateVo reportConfigSaveOrUpdateVo){
        reportConfigService.saveReportConfig(reportConfigSaveOrUpdateVo);
        return ReturnResult.success("ok");
    }

    @ApiOperation("根据期数和resourceId查询设置的班级")
    @RequestMapping(value = "/findClassReportConfigs", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult< List<ClassReportConfig>> saveReportConfigs(@RequestParam("periodIds")List<Long> periodIds,@RequestParam("resourceId")long resourceId,@ApiParam("1 双向剔除，2单向剔除")@RequestParam("type")int type){
        List<ClassReportConfig>   classReportConfigs= reportConfigService.findReportClassByPeriodIdsResourceId(periodIds, resourceId,type);
        return ReturnResult.success(classReportConfigs);
    }

    @ApiOperation("根据期数ids获取非作废班级")
    @RequestMapping(value = "/findUseCourseListByPeriodIds", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Map<Long, List<CourseClass>>> findUseCourseListByPeriodIds(@RequestParam("periodIds")List<Long> periodIds){

        List<CourseClass> courseClassList=courseClassService.findUseCourseClassByPeriodIds(periodIds, CourseClass.BASE_FIELDS);
        Map<Long, List<CourseClass>> periodClassMap = BeanUtils.toGroup(courseClassList, "periodId");
        return ReturnResult.success(periodClassMap);
    }

    @ApiOperation("退费扣除表")
    @RequestMapping(value = "/findStudentRefundBonusPersonPage", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Page<StudentRefundDetailVo>> findStudentRefundBonusPersonPage(StudentRefundQueryVo studentRefundQueryVo, @RequestParam(value = "pageNo", defaultValue = "1") int pageNo, @RequestParam(value = "pageSize", defaultValue = "20") int pageSize,HttpServletRequest request){
        DataPermission dataPermission = getDataPermission(request);
        Page<StudentRefundDetailVo> studentRefundBonusPersonPage = indexStatisticsService.findStudentRefundBonusPersonPage(studentRefundQueryVo, dataPermission, pageNo, pageSize);
        return ReturnResult.success(studentRefundBonusPersonPage);
    }


    @ApiOperation("导出退费扣除表")
    @RequestMapping(value = "/exportStudentRefundBonusPerson",method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Void> exportStudentRefundBonusPerson(StudentRefundQueryVo studentRefundQueryVo, HttpServletRequest request,HttpServletResponse response)throws  IOException{
        DataPermission dataPermission = getDataPermission(request);
        Webs.writeExcel(request,response,indexStatisticsService.exportStudentRefundBonusPerson(studentRefundQueryVo,dataPermission) ,"退费扣除表");
        return ReturnResult.success("ok");
    }

    @ApiOperation("锁定提成者")
    @RequestMapping(value = "/lockBonusPerson", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Void> lockBonusPerson(@RequestParam(value = "studentRefundIds") String studentRefundIds,HttpServletRequest request){
        refundBonusPersonService.saveRefundBonusPerson(Utils.toLongIds(studentRefundIds));
        return ReturnResult.success("ok");
    }


    @ApiOperation("解锁提成者")
    @RequestMapping(value = "/unlockBonusPerson", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Void> unlockBonusPerson(@RequestParam(value = "studentRefundIds") String studentRefundIds,HttpServletRequest request){
        refundBonusPersonService.deleteByStudentRefundIds(Utils.toLongIds(studentRefundIds));
        return ReturnResult.success("ok");
    }

    @ApiOperation("学科续读率")
    @RequestMapping(value = "/findPeriodSubjectContinue", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<List<PeriodSubjectContinueVo>> findExternalCampusReg(@RequestParam("areaTeamId")long areaTeamId, @RequestParam("periodId")long periodId, HttpServletRequest request) {
        List<PeriodSubjectContinueVo> periodSubjectContinues = indexStatisticsService.findPeriodSubjectContinue(areaTeamId, periodId, this.getDataPermission(request));
        return ReturnResult.success(periodSubjectContinues);
    }


    @ApiOperation("导出学科续读率")
    @RequestMapping(value = "/exportPeriodSubjectContinue",method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Page<CounselorBranchBonusVo>> exportPeriodSubjectContinue(@RequestParam(value = "areaTeamId")long areaTeamId,@RequestParam("periodId")long periodId, HttpServletRequest request,HttpServletResponse response)throws  IOException{

        Webs.writeExcel(request,response,indexStatisticsService.exportPeriodSubjectContinue(areaTeamId,periodId,this.getDataPermission(request)) ,"学科续读率");
        return ReturnResult.success("ok");
    }

    @ApiOperation("教师续读率学科指标")
    @RequestMapping(value = "/findPeriodSubjectTeacherContinue", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<List<PeriodSubjectTeacherContinueVo>> findPeriodSubjectTeacherContinue(@RequestParam(value = "teacherName",required = false)String teacherName,@RequestParam("areaTeamId")long areaTeamId, @RequestParam("periodId")long periodId, HttpServletRequest request) {
        List<PeriodSubjectTeacherContinueVo> periodSubjectTeacherContinues = indexStatisticsService.findPeriodSubjectTeacherContinue(areaTeamId, periodId, teacherName,this.getDataPermission(request));
        return ReturnResult.success(periodSubjectTeacherContinues);
    }


    @ApiOperation("导出教师续读率学科指标")
    @RequestMapping(value = "/exportPeriodSubjectTeacherContinue",method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Page<CounselorBranchBonusVo>> exportPeriodSubjectTeacherContinue(@RequestParam(value = "teacherName",required = false)String teacherName,@RequestParam(value = "areaTeamId")long areaTeamId,@RequestParam("periodId")long periodId, HttpServletRequest request,HttpServletResponse response)throws  IOException{

        Webs.writeExcel(request,response,indexStatisticsService.exportPeriodSubjectTeacherContinue(areaTeamId,periodId,teacherName,this.getDataPermission(request)) ,"教师续读率学科指标");
        return ReturnResult.success("ok");
    }

    @ApiOperation("教师任教情况(学科指标)")
    @RequestMapping(value = "/findTeacherTeachDetailPage", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<List<TeacherTeachDetailVo>> findTeacherTeachDetailPage(@Valid @ModelAttribute TeacherTeachDetailQueryVo teacherTeachDetailQueryVo,@RequestParam("pageNo")int pageNo, @RequestParam("pageSize")int pageSize,HttpServletRequest request) {
        Page<TeacherTeachDetailVo> teacherTeachDetailPage = indexStatisticsService.findTeacherTeachDetailPage(this.getDataPermission(request), teacherTeachDetailQueryVo, pageNo, pageSize);
        return ReturnResult.success(teacherTeachDetailPage);
    }


    @ApiOperation("导出教师任教情况(学科指标)")
    @RequestMapping(value = "/exportTeacherTeachDetailPage",method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Page<CounselorBranchBonusVo>> exportPeriodSubjectTeacherContinue(@Valid @ModelAttribute TeacherTeachDetailQueryVo teacherTeachDetailQueryVo, HttpServletRequest request,HttpServletResponse response)throws  IOException{

        Webs.writeExcel(request,response,indexStatisticsService.exportTeacherTeachDetail(this.getDataPermission(request),teacherTeachDetailQueryVo) ,"教师任教情况(学科指标)");
        return ReturnResult.success("ok");
    }

}
